Как мне применить react-native-swiper в теге View?

#javascript #reactjs #react-native #react-native-swiper

#javascript #reactjs #react-native #реагировать-родной-swiper #react-native-swiper

Вопрос:

Я пишу, чтобы получить некоторую помощь из-за приложения fact-native-sweeper, которое сработало не так хорошо, как я думал.

Первый код — это код макета с другим заголовком, разделом и нижним колонтитулом в представлении контейнера.

Второй код — это код, который добавляет swiper в раздел первого кода. Я ожидал, что размер верхнего и нижнего колонтитулов будет фиксированным, а sweeper будет полностью напечатан в разделе.

Однако раздел вторгается в область верхнего и нижнего колонтитулов, и в то же время вид верхнего колонтитула становится меньше, а вид нижнего колонтитула не виден.

Возможно, я вызвал ошибку, все еще изучая real-native. Я был бы признателен, если бы вы оставили комментарий об ошибке и направлении улучшения.

Спасибо, что прочитали длинную статью.

  • Первый код
 // Code 1
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class extends React.Component {
  render(){
    return (
      <View style={styles.container}>
        {/* header */}
        <View style={styles.header}>
          <Text>header</Text>
        </View>

        {/* section */}
        <View style={styles.section}>
          <Text>sect</Text>
        </View>


        <View style={styles.footer}>
          <Text>footer</Text>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff'
  },
  header:{
    flex:1.5,
    backgroundColor:"red"
  },
  section:{
    flex:8,
    backgroundColor:"yellow"
  },
  footer:{
    flex:1,
    backgroundColor:"blue"
  }
});

  
  • Второй код
 import React from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native'
import Swiper from 'react-native-swiper/src'



export default class extends React.Component {
  render(){
    return (
      <View style={styles.container}>

        {/* header */}
        <View style={styles.header}>
          <Text>header</Text>
        </View>


        {/* section */}
        <View style={styles.section}>
          <Swiper 
          style={styles.wrapper}
          showsPagination={false}
          >
            <View style={styles.slide1}>
              <Text style={styles.text}>Hello Swiper</Text>
            </View>
            <View style={styles.slide2}>
              <Text style={styles.text}>Beautiful</Text>
            </View>
            <View style={styles.slide3}>
              <Text style={styles.text}>And simple</Text>
            </View>
          </Swiper>
        </View>



        {/* header */}
        <View style={styles.footer}>
          <Text>footer</Text>
          {/* <Header /> */}
        </View>

      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff'
  },
  header:{
    flex:1.5,
    backgroundColor:"red"
  },
  section:{
    flex:8,
    backgroundColor:"yellow"
  },
  footer:{
    flex:1,
    backgroundColor:"blue"
  },
  wrapper:{

  },
  slide1: {
    flex:1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#9DD6EB'
  },
  slide2: {
    flex:1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#97CAE5'
  },
  slide3: {
    flex:1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#92BBD9'
  },
  text: {
    color: '#fff',
    fontSize: 30,
    fontWeight: 'bold'
  }

});


AppRegistry.registerComponent('App/', () => App)[ie][1]