Close react native modal by clicking on overlay?

前端 未结 13 659
梦如初夏
梦如初夏 2020-12-23 14:27

Is it possible to close react native modal by clicking on overlay when transparent option is true? Documentation doesn\'t provide anything about it

13条回答
  •  感情败类
    2020-12-23 14:32

    Here is my perfectly working solution

    MODAL CODE:

    const ListInModal = ({ showListModal, onClose, data, onSelectItem }) => {
      return (
         onClose(false)}>
           onClose(false)} style={styles.centeredView}>
            
              
                {data.map((item, index) => (
                  <>
                     {
                        onSelectItem(item);
                        onClose(false);
                      }}
                      style={{ height: 43, justifyContent: 'center' }}
                    >
                      {item.label}
                    
                    {index <= data.length - 2 && (
                      
                    )}
                  
                ))}
              
            
          
        
      );
    };
    

    STYLING:

    const styles = StyleSheet.create({
      centeredView: {
        flex: 1,
        justifyContent: 'center',
        backgroundColor: '#00000099',
      },
      modalView: {
        marginHorizontal: wp('5%'),
        marginVertical: hp('10%'),
        backgroundColor: colors.popupBlack,
        borderRadius: 20,
        shadowColor: '#000',
        shadowOffset: {
          width: 0,
          height: 2,
        },
        shadowOpacity: 0.25,
        shadowRadius: 3.84,
        elevation: 5,
      },
      itemLabel: {
        fontSize: wp('5%'),
        color: colors.white,
        paddingHorizontal: (24 / 375) * screenWidth,
      },
    });
    

    USAGE:

     setshowListModal(bool)}
      onSelectItem={(item) => onPressApplicationType(item.label)}
    />
    

提交回复
热议问题