任何人都知道如何从组件SetIsOpen中更改BottomSheetBtn的真正值?我想我试过了我知道的每一件事,但结果我不可能
import { StyleSheet, Text, View } from 'react-native';
import BottomSheet, {BottomSheetView} from '@gorhom/bottom-sheet';
import { TextInput } from 'react-native-gesture-handler';
import BottomSheetBtn from './BottomSheetBtn';
export default function UserInksBottomSheet(){
const sheetRef = useRef<BottomSheet>(null);
const [isOpen, SetIsOpen] = useState(true);
const snapPoints = ['60%','90%']
return(
<BottomSheet
ref={sheetRef}
snapPoints={snapPoints}
>
<BottomSheetView style={styles.container}>
BOTTOMSHEET CONTENT
<BottomSheetBtn/> <--- This button is which needs to change the state
</BottomSheetView>
</BottomSheet>
);
}```发布于 2022-08-05 11:54:28
只需将其作为主要组件中的道具传递:
<BottomSheetBtn isOpen={isOpen} SetIsOpen={SetIsOpen}/>将BottomSheet组件中的值更改为正则函数:
const changeValue = () => props.SetIsOpen(!props.isOpen)发布于 2022-08-05 12:22:04
将setIsOpen函数传递给BottomSheetBtn组件的onPress功能。
<BottomSheetBtn onPress={() => SetIsOpen(!isOpen)}/> // this will provide the toggle functionality. 然后将onPress道具传递给BottomSheetBtn主体中的TouchableOpacity或Button组件。
<TouchableOpacity onPress={props.onPress} >
{...}
</TouchableOpacity>https://stackoverflow.com/questions/73249292
复制相似问题