2017-04-24 2 views
0

私はreact-native-modalboxを使用しています。下の画像の暗い影の部分で判断すると、私のモデルは、それが内部にあるコンポーネントのコンテキストで止まっています。アプリ全体ではありません。モーダルがルートコンポーネントレベルにあると思うようにする方法はありますか?私はzIndex:500を試しましたが動作しません。子コンポーネントコンテキストで反応したネイティブモダルボード

enter image description here

モーダル:

enter image description here

コード:

let Categories = (props) => (
    <View style={styles.formItem}> 
    <List style={styles.list} dataArray={props.categories} 
     renderRow={(item) => 
     <ListItem icon onPress={() => props.toggleShowSubcategories(item)}> 
      <Left> 
      <Icon 
       style={styles.icon} 
       name={item.icon} 
       size={20} 
       color={item.iconColor} /> 
      </Left> 
      <Body> 
      <Text style={styles.label}>{item.label}</Text> 
      </Body> 
      <Right> 
      <Icon style={styles.arrow} name="angle-right" size={20} /> 
      </Right> 
     </ListItem> 
     }> 
    </List> 

    <Modal 
     style={[styles.modal, styles.modal3]} 
     position={'center'} 
     isOpen={props.categories.some(x => showModal(x))}> 
     <Text style={styles.text}>Modal centered</Text> 
     <Button 
     onPress={() => props.setAllShowSubcategoriesToFalse()} 
     style={styles.btn}><Text>Close</Text></Button> 
    </Modal> 
    </View> 

) 

Categories.propTypes = { 
    categories: React.PropTypes.array.isRequired, 
    toggleSubcategory: React.PropTypes.func.isRequired, 
    toggleShowSubcategories: React.PropTypes.func.isRequired, 
    setAllShowSubcategoriesToFalse: React.PropTypes.func.isRequired 
} 

Categories = connect(
    mapStateToProps, 
    mapDispatchToProps 
)(Categories) 

export default Categories 

const styles = { 
    list: { 
    flex: 1, 
    backgroundColor: '#FFFFFF', 
    borderRadius: 8 
    }, 
    label: { 
    color: '#9E9E9E', 
    fontWeight: '200' 
    }, 
    formItem: { 
    marginBottom: 10 
    }, 
    icon: { 
    width: 30 
    }, 
    header: { 
    backgroundColor: '#F7F7F7', 
    }, 
    arrow: { 
    color: '#9E9E9E' 
    }, 
    modalView: { 
    flex: 1, 
    backgroundColor: '#FFFFFF', 

    borderRadius: 8, 
    }, 
    title: { 
    color: '#9E9E9E', 
    fontWeight: '200' 
    }, 


    wrapper: { 
    paddingTop: 50, 
    flex: 1 
    }, 

    modal: { 
    justifyContent: 'center', 
    alignItems: 'center', 
    zIndex: 500 
    }, 

    modal3: { 
    height: 500, 
    width: 300, 
    backgroundColor: 'red', 
    zIndex: 500 
    }, 

    btn: { 
    margin: 10, 
    backgroundColor: '#3B5998', 
    color: 'white', 
    padding: 10 
    }, 

    btnModal: { 
    position: 'absolute', 
    top: 0, 
    right: 0, 
    width: 50, 
    height: 50, 
    backgroundColor: 'transparent' 
    }, 

    text: { 
    color: 'black', 
    fontSize: 22 
    } 
} 

答えて

0

親ビューのみスタイリングのスタイル 'FormItemのは、' 'marginBottom:10' でいます。スクリーン全体を塗りつぶすためのビューを子供に合わせるように指示するものは何もありません。ビューを 'absoluteFill'スタイルにして、画面いっぱいになるようにします。https://til.hashrocket.com/posts/202dfcb6c4-absolute-fill-component-in-react-native

+0

ありがとうございました。それはちょうどそれに 'position:absolute'を与えます。うまくいきません。 – BeniaminoBaggins

+0

問題の例をhttps://snack.expo.io/に入れておくことは価値があるかもしれません。これはReactのjsfiddleに似ています。そうすれば、コードを実行して作業することができます。 – reggie3

関連する問題