Skip to content

Instantly share code, notes, and snippets.

@terrysahaidak
Created March 17, 2023 19:33
Show Gist options
  • Save terrysahaidak/e732c6ea5df748dfb2b66e0adbdd6e45 to your computer and use it in GitHub Desktop.
Save terrysahaidak/e732c6ea5df748dfb2b66e0adbdd6e45 to your computer and use it in GitHub Desktop.
const KeyboardAvoidingView = (props) => {
const behavior = props.behavior;
const keyboard = useAnimatedKeyboard();
const insets = useSafeAreaInsets();
const animatedStyle = useAnimatedStyle(() => {
const value = keyboard.height.value - insets.bottom;
if (behavior === 'height') {
return {
height: value,
flex: 0,
};
}
if (behavior === 'padding') {
return {
paddingBottom: value,
};
}
if (behavior === 'position') {
return {
bottom: value,
};
}
return {
};
});
return (
<Reanimated.View style={StyleSheet.compose(props.style, animatedStyle)}>
{props.children}
</Reanimated.View>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment