|
| 1 | +import React, { useEffect } from 'react'; |
| 2 | +import { TouchableOpacity, View, Text, StyleSheet } from 'react-native'; |
| 3 | +import { useNavigation } from '@react-navigation/native'; |
| 4 | + |
| 5 | +const ModalView = () => { |
| 6 | + useEffect(() => { |
| 7 | + console.log('ModalView mounted'); |
| 8 | + }, []); |
| 9 | + |
| 10 | + const navigation = useNavigation(); |
| 11 | + return ( |
| 12 | + <View style={styles.container}> |
| 13 | + <Text> |
| 14 | + This is the outer modal. If you try to open it from the inner modal, it |
| 15 | + doesn't work. But if you comment out the `presentation: modal` on the |
| 16 | + inner modal, it does work! In addition, if opening a modal in the same |
| 17 | + navigator stack also works. |
| 18 | + </Text> |
| 19 | + <TouchableOpacity onPress={() => navigation.navigate('modal-2')}> |
| 20 | + <View style={styles.button}> |
| 21 | + <Text style={styles.buttonText}>Open sibling outer modal.</Text> |
| 22 | + </View> |
| 23 | + </TouchableOpacity> |
| 24 | + <TouchableOpacity onPress={() => navigation.goBack()}> |
| 25 | + <View style={styles.button}> |
| 26 | + <Text style={styles.buttonText}>Back</Text> |
| 27 | + </View> |
| 28 | + </TouchableOpacity> |
| 29 | + </View> |
| 30 | + ); |
| 31 | +}; |
| 32 | + |
| 33 | +const styles = StyleSheet.create({ |
| 34 | + container: { |
| 35 | + flex: 1, |
| 36 | + justifyContent: 'center', |
| 37 | + alignItems: 'center', |
| 38 | + backgroundColor: 'green', |
| 39 | + }, |
| 40 | + button: { |
| 41 | + width: 200, |
| 42 | + height: 50, |
| 43 | + justifyContent: 'center', |
| 44 | + alignItems: 'center', |
| 45 | + borderRadius: 5, |
| 46 | + backgroundColor: 'blue', |
| 47 | + }, |
| 48 | + buttonText: { |
| 49 | + color: 'white', |
| 50 | + }, |
| 51 | +}); |
| 52 | + |
| 53 | +export default ModalView; |
0 commit comments