Closed douglasrcjames closed 4 years ago
Same for me. Looking into this
I am having the same issue (insets are 0
) but nothing stands out for me which is different from the implementation in the example app. The example app gives my ~42
as top and bottom insets on my android phone but is always 0
in my project. Upon deeper investigation these are always 0
:
https://github.com/th3rdwave/react-native-safe-area-context/blob/1628d2e3875831d39423e82c4012ef5b956dce7e/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.java#L57
windowInsets.top = Math.max(windowInsets.top - visibleRect.top, 0);
windowInsets.left = Math.max(windowInsets.left - visibleRect.left, 0);
windowInsets.bottom = Math.max(visibleRect.top + view.getHeight() + windowInsets.bottom - windowHeight, 0);
windowInsets.right = Math.max(visibleRect.left + view.getWidth() + windowInsets.right - windowWidth, 0);
I am mainly testing on iOS right now, but I am sure I will need it to work on Android side as well. Not sure what you mean by "having the same issue but nothing stands out".
I have posted a better-formatted question on StackOverflow and will report back if I find a solution: https://stackoverflow.com/questions/64454207/keyboardavoidingview-react-navigation-safe-area-view-not-working
Have you tried wrapping your App in SafeAreaProvider?
export default class App extends Component {
render(){
return (
<SafeAreaProvider>
...
</SafeAreaProvider>
);
}
}
Yep I have a provider at the top level
@alexandersandberg Wrapping the app in SafeAreaProvider
fixes the issue and the insets now properly return values. Thanks! I am still having an issue with React Navigation working nicely, but that's not relevant to this thread.
still getting this despite use of <SafeAreaProvider />
@alexandersandberg Same here.
I rewrote CustomKeyboardAvoidingView little bit (work for me):
function CustomKeyboardAvoidingView({children, style}: any) {
const insets = useSafeAreaInsets();
const headerHeight = useHeaderHeight();
return (
<KeyboardAvoidingView
style={StyleSheet.compose(style, {marginBottom: insets.bottom})}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
enabled={true}
keyboardVerticalOffset={headerHeight + insets.bottom}>
{children}
</KeyboardAvoidingView>
);
}
usage:
useSafeAreaInsets useHeaderHeight
where are useSafeAreaInsets
and useHeaderHeight
defined?
useSafeAreaInsets useHeaderHeight
where are
useSafeAreaInsets
anduseHeaderHeight
defined?import {useSafeAreaInsets} from 'react-native-safe-area-context'; import {useHeaderHeight} from '@react-navigation/elements';
If you're developing with Expo and didn't explicitly do anything that could affect the AndroidManifest.xml file, make sure you have
More details here: https://github.com/th3rdwave/react-native-safe-area-context/issues/124#issuecomment-1518126533
I am trying to fix an issue while using the tab navigator and/or Safe Area where my keyboardAvoidingView is covering the message input box on the chat screen when the keyboard is brought up. Not sure what the culprit is exactly, but I am pretty sure it's the safeview padding on top and/or bottom, which I have learned are the "insets". I am trying to use
useSafeAreaInsets
, but all the values return 0! (See inCustomKeyboardAvoidingView
) I want to use those insets to add to thekeyboardVerticalOffset
param so the avoiding view works properly. I tried setting thekeyboardVerticalOffset
to a flat value, but it seems to be different depending on the device, aka the inset padding values would make sense. I like the style of the tab bar right now, so I'd like to keep it with an increased height and padding and font size, but maybe I am doing it wrong with react native navigation? Regardless, the insets should be returning a value.I tried using the solution outlined in this issue: https://github.com/th3rdwave/react-native-safe-area-context/issues/54
Here is my App.js code recreating the issue:
package.json