-
-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KeyboardAwareScrollView: justifyContent: "space-between" is not working properly in contentContainerStyle #645
Comments
Inside const view = useAnimatedStyle(
() =>
enabled
? {
// animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)
// this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
// by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
// from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
// re-calculation on every animation frame and it helps to achieve smooth animation.
// see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
paddingBottom: currentKeyboardFrameHeight.value + 1,
}
: {},
[enabled],
);
return (
<ScrollViewComponent
ref={onRef}
{...rest}
scrollEventThrottle={16}
onLayout={onScrollViewLayout}
>
{children}
<Reanimated.View style={view} />
</ScrollViewComponent>
); The |
Hi @Isaccobosio Thank you for raising this problem 🙌 I'll split my answer in two parts: 1️⃣ Why
|
Hi @kirillzyusko , thank you very much for the answer! The situation is clear. I understand that the Reanimated.View is essential for the purpose of this library. What about to set the Reanimated.View with an initial height of 0? I haven't test it but it may helps. Anyway, with |
Do you want it to be like
Well, definitely yes 😔 Can you try to use the code that I gave to you (where you specify |
I don't know if this might be a solution. I need to try it. I can try it later and I'll let you know for sure!
It could work! I can try this as well 👍🏻 |
Yeah, please test and let me know how it works 🙌 |
Hey @kirillzyusko Sorry for the late answer but it was a hard week. First test: use the
|
without the space between | with the space between |
---|---|
Second test: currentKeyboardFrameHeight.value condition
What I found is that setting the height of the Reanimated View based on currentKeyboardFrameHeight
value has no effect.
Even if a View has a height set to 0, it is part of the parent View.
So I tried something like this
const view = useAnimatedStyle(
() =>
enabled
? {
// animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)
// this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
// by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
// from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
// re-calculation on every animation frame and it helps to achieve smooth animation.
// see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
paddingBottom: currentKeyboardFrameHeight.value + 1,
display: currentKeyboardFrameHeight.value === 0 ? "none" : "flex",
}
: {},
[enabled],
);
return (
<ScrollViewComponent
ref={onRef}
{...rest}
scrollEventThrottle={16}
onLayout={onScrollViewLayout}
>
{children}
<Reanimated.View style={view} />
</ScrollViewComponent>
);
With this approach it works because it effectively dismount the reanimated view. But as soon as the keyboard is presented it "flicker". Video down below
Simulator.Screen.Recording.-.iPhone.13.-.2024-10-26.at.18.26.02.mp4
Conclusion
I don't know how to handle this situation and which is the best solution.
I hope that you have better ideas!
cheers!
Sorry for a late response @Isaccobosio So it looks like first approach is actually working for you? 🤔 Regarding second solution - I think you can interpolate const keyboardFrame = interpolate(
e.height,
[0, keyboardHeight.value],
[0, keyboardHeight.value + extraKeyboardSpace + 1],
);
currentKeyboardFrameHeight.value = keyboardFrame; Would you mind to check that solution? I think it shouldn't hurt performance a lot (let me know if this solution works for you and then I can check on a low end device the FPS) 😊 |
Describe the bug
Configuring the property
contentContainerStyle
forKeyboardAwareScrollView
withjustifyContent: "space-between"
does not work as expected.If I do the same thing with
ScrollView
it works fine.Code snippet
Expected behavior
As a Scrollview, I expect that the two
View
inside theKeyboardAwareScrollView
is positioned with a space between them.What I am trying to create is a screen in the upper part of which there is a login form and in the lower part buttons for logging in with the various societies.
If the screen size is not large enough, the two main components will have to scroll.
Screenshots
Smartphone
Additional context
I also tried to put a
View
between the two main Views like this:But this is the result:
As you can see in the bottom of the screen there is a little blue space (maybe a pixel). This means that the two Views are not displayed correctly. Is like a ghost View is displayed:
The text was updated successfully, but these errors were encountered: