下午好,亲爱的朋友们。我现在对每个动作都执行了调度。我只需要在挂载页面时调度一次,在卸载页面时将其删除。告诉我如何做到这一点。
const myRef = createRef<any>();
const KeyboardAvoidingWrapper: React.FC<IKeyboardAvoidingProps> = (
props: IKeyboardAvoidingProps,
) => {
const dispatch = useDispatch();
dispatch(setReference(myRef));
if (isAndroid) {
return (
<ScrollView ref={myRef} style={styles.scroll} contentContainerStyle={styles.scrollContent}>
<KeyboardAvoiding>{props.children}</KeyboardAvoiding>
</ScrollView>
);
}
return (
<KeyboardAwareScrollView
ref={myRef}
style={styles.scroll}
extraHeight={40}
contentContainerStyle={styles.scrollContent}
>
{props.children}
</KeyboardAwareScrollView>
);
};