React Native:RN-Material-Dropdown未显示(iOS)

时间:2018-05-25 17:22:22

标签: javascript react-native react-native-android react-native-ios

我正在尝试使用iOS上的lib react-native-material-dropdown ,在iPad Air上运行,但是屏幕上没有显示下拉列表。我试图输入一个带负值和宽度值的marginTop,但没有任何效果。按照我的类的代码和我正在使用的版本:

RN版本:0.55 RN材料下拉版本:0.11.1 我的班级代码:

  

DetailProduct.js

{/* imports */}

export default class DetailProduct extends React.Component {
  constructor(props){
    super(props);

   this.state = {
      sizes: [{value: 'Eleonora'}, {value: 'Barbosa'}, {value: 'Rafaela'}], 
    };
  }

  {/* ... */}

  render() {

    return (
      <View style={styles.container}>

        <View style={styles.baseContent}>
          <View style={styles.contentLeft}>
            <View style={styles.baseProductDetails}>
              <View style={styles.baseCodeSizeColor}>  

                <TouchableOpacity style={styles.baseSize} onPress={() => {
                  <View style={{width: 200, backgroundColor: '#BDBDBD', marginTop: -15, justifyContent: 'flex-start'}}>
                    <Dropdown
                        rippleCentered={true}
                        label='Favorite Fruit'
                        itemCount={4}
                        containerStyle={{borderWidth: 1, borderColor: 'lightgrey',}}
                        dropdownPosition={50}
                        data={[{value: 'Eleonora'}, {value: 'Barbosa'}, {value: 'Rafaela'}]} />    
                  </View>      
                  }} activeOpacity={0.9}>
                  <Image source={require('../imgs/assets/icon_size_product.png')} style={styles.icSize} />
                  <Text style={styles.txtSizeProduct}>Tamanho: Masculino Unico</Text>
                  <Image source={require('../imgs/assets/icon_dropdown_app.png')} style={styles.icDropdownSize} />
                </TouchableOpacity>
                {/* ... */}
              </View>
            </View>
          </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({      
  container: {
    flex: 1,
    padding: 30,
    backgroundColor: '#F5F5F5',
    flexDirection: 'column',
  },
  baseContent: {
    flexWrap: 'wrap',
    height: '90%',
    marginTop: 90,
    flexDirection: 'row',
  },
  contentLeft: {
    flexDirection: 'column',
    width: '50%',
    height: '100%',
    flexWrap: 'wrap',
    marginRight: '2%',
    shadowColor: '#212121',
    shadowOffset: {width: 0,height: 3},
    shadowOpacity: 0.16,
  },
  contentRight: {
    width: '46%',
    flexWrap: 'wrap',
    marginLeft: '2%',
  },
  baseSize: {
    width: '48%',
    alignItems: 'center',
    marginRight: 8,
    alignSelf: 'stretch',
    flexDirection: 'row',
  },
  txtSizeProduct:{
    color: '#FFFFFF',
    fontSize: 12,
  },
  icDropdownSize: {
    width: 12,
    height: 11,
    position: 'absolute', 
    right: 15,
    top: 3
  },
  icSize: {
    width: 17,
    height: 17,
    marginRight: 6,
    resizeMode: 'contain'
  },
});

1 个答案:

答案 0 :(得分:0)

我认为您可以试用React Hooks。

function DetailProduct() {
  const sizes = [
    { value: "Eleonora" },
    { value: "Barbosa" },
    { value: "Rafaela" }
  ];
  return (
    /* ...*/
    <TouchableOpacity
      style={styles.baseSize}
      onPress={() => {
        <View
          style={{
            width: 200,
            backgroundColor: "#BDBDBD",
            marginTop: -15,
            justifyContent: "flex-start"
          }}
        >
          <Dropdown
            label="Favorite Fruit"
            itemCount={4}
            containerStyle={{ borderWidth: 1, borderColor: "lightgrey" }}
            dropdownPosition={50}
            data={sizes}
          />
        </View>;
      }}
      activeOpacity={0.9}
    >
      /*...*/
    </TouchableOpacity>
    /* ... */
  );
}

const styles = StyleSheet.create({ 
/*...*/
});