-
-
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: scroll only when needed #168
Comments
It seems like
Yes, I agree with it. I had a plan to include this component in the library (like an alternative to P. S. that's how demo-kasv.mp4 |
Awesome, I agree with your take on capturing the input coordinates instead of the view. And thanks for the demo and explanation, will debug what I'm doing wrong. |
Figured out what happened. I was passing |
@kirillzyusko I think I need your input here. I noticed the provided example doesn't work properly if you need the scroll view's content to fill the available space. Once I add CleanShot.2023-06-08.at.08.12.28.mp4While it works smoothly without the flex-grow, if you need to center the content of the scroll view, you have no workaround. Have you seen this before? Minimal repro: const styles = StyleSheet.create({
centered: {
alignItems: "center",
flex: 1,
justifyContent: "center",
},
container: {
flex: 1,
},
contentContainer: {
backgroundColor: "#f7d7d7",
flexGrow: 1,
},
});
const Centered: FC<{ children: ReactNode }> = ({ children }) => (
<View style={styles.centered}>{children}</View>
);
function randomColor() {
return "#" + Math.random().toString(16).slice(-6);
}
export function AwareScrollView() {
useResizeMode();
return (
<KeyboardAwareScrollView
contentContainerStyle={styles.contentContainer}
style={styles.container}
>
<Centered>
{new Array(4).fill(0).map((_, i) => (
<TextInput
key={i}
placeholder={`${i}`}
placeholderTextColor="black"
style={{
width: "100%",
height: 50,
backgroundColor: randomColor(),
marginTop: 50,
}}
/>
))}
</Centered>
</KeyboardAwareScrollView>
);
} |
Hi @MarceloPrado That's strange - current behaviour looks like a KeyboardAvoidingView 🤷♂️ |
Hi @kirillzyusko, just a friendly ping - had you had any time to investigate this issue? Thanks in advance! |
Not exactly this issue, but I've got some requests of what could be improved in the library when you have to deal with avoiding functionality and I was busy with that - was trying to design a new API/integrate new functionality into existing methods and got some success. New Overall the new version of My expectation is that new release preparation will take about a month and after that I will switch to resolving all opened issues including this one |
That's awesome @kirillzyusko, I'm happy to hear you're coming up with a more powerful API. This is such an important (and hard) problem in the current React Native ecosystem 🙂 I hope everything works out as you expect in the new API. Let me know if you need any help testing these cases, happy to help. |
video.mp4when i focus on TextInput 5, it is a space between textinput and keyboard. how can i make it exaclty fit ? |
@NguyenHoangMinhkkkk this is because everything depends on touch area (if you are using version below In |
@MarceloPrado I had a look on this problem. It happens because Since your content is in center and you add an empty view - your content will be pushed up to stay in the center. To overcome this problem you can use const props = useAnimatedProps(() => ({
contentInset: {
bottom: fakeViewHeight.value,
},
}));
return (
<Reanimated.ScrollView
ref={scrollViewAnimatedRef}
{...rest}
onScroll={onScroll}
animatedProps={props}
scrollEventThrottle={16}
>
{children}
{/*<Reanimated.View style={view} />*/}
</Reanimated.ScrollView> Such inset don't affect content position, but it works only on iOS (since BTW if you have any suggestions how to fix this problem - I'll be glad to hear them 😊 |
New version 1.7.0 with Aware Scroll View & KeyboardAvoidingView is amazing. The only problem that I figure out while testing is IOS behavior. Aware Scroll View issue:
Attaching detailed demo: Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-09-09.at.14.59.34.mp4As you said before I believe it takes much more time to investigate all these moments including multiline input handling. Thanks a lot for your job, you made a huge impact for resolving a painful Keyboard handling for react-native 🙂. |
@VladyslavMartynov10 is it iOS feature to scroll to the input if it's not visible and you are typing something? Or iOS just dispatched onStart/onEnd events from keyboard lifecycle? Basically, if you need to maintain TextInput visible while typing - you can achieve that just by calling |
I'm not sure if iOS has this functionality out of the box, but it seems that only 'onStart' and 'onEnd' events are dispatched during the keyboard lifecycle. Thanks for the |
@VladyslavMartynov10 I investigated this topic a little bit more and it seems like iOS fires Screen.Recording.2023-09-11.at.13.02.25.movI don't know why it happens in this way, but it seems like Apple engineers needed in this functionality 😅 So I'd suggest you to go with calling |
@kirillzyusko Thanks! Recently I've created the new Swift UI project in order to be sure that the problem lies in IOS implementation itself. This feature is not supported out of box, so we have to create our own logic. I don't know why Apple doesn't include it, sounds funny 😅. So yeah |
@kirillzyusko sorry for the delay, if possible, let's try keeping this issue to the original thread to ensure we're all talking about the same thing 🙂 To recap for everyone, the existing @kirillzyusko I have to spend some time prototyping. One immediate approach I can think of is to add a top "dummy" view to counter the bottom one in this case. I'm not sure how the "syncing" would happen. Not very fond of this since it's easy to get messy. One other way: when the keyboard is shown, I think it's valid to assume we don't want to "respect" the vertically centered layout. I wonder if we could de-activate |
@MarceloPrado Cool idea. I think it will compensate the movement, but in casual scenarios (when you have a lot of TextInputs and they take more space than height of the screen) after keyboard is shown you'll be able to scroll to top and you will see this "fake" view.
@MarceloPrado we can de-activate these styles by setting I've also tried to use Another approach that I was going to check was to use |
Recently I was trying to migrate to new version 1.9.4 and lost scroll-to-focused input effect at least on Android. For now when the input is focused and under keyboard, maybeScrollCallback never fires. I've realised that we've got a discussion before #168 (comment) with the support of this feature, but I think it should be handled somehow on native side in order to avoid multiple calls of the same callback in RN. Any ideas how it can be achieved without reinventing the wheel & performance lost? Thanks beforehand 🙂! |
Hello @VladyslavMartynov10 👋 Would you mind to create a new issue? I remember your problem (to keep focused input in visible area while user is typing) and I have some ideas on how to handle it on a So, please, create a new issue and we will discuss an approach with you there (don't want to mix different problems in this single issue). |
@kirillzyusko Did it |
Another workaround was discovered in #405 - you can specify const STATUS_BAR_HEIGHT = 44;
const HEADER_HEIGHT = 56;
const styles = StyleSheet.create({
centered: {
alignItems: "center",
flex: 1,
justifyContent: "center",
minHeight:
Dimensions.get("window").height - STATUS_BAR_HEIGHT - HEADER_HEIGHT, // <- fix is here
},
container: {
flex: 1,
},
contentContainer: {
backgroundColor: "#f7d7d7",
flexGrow: 1,
},
});
const Centered: FC<{ children: ReactNode }> = ({ children }) => (
<View style={styles.centered}>{children}</View>
);
function randomColor() {
return "#" + Math.random().toString(16).slice(-6);
}
export default function AwareScrollView() {
useResizeMode();
return (
<KeyboardAwareScrollView
contentContainerStyle={styles.contentContainer}
style={styles.container}
>
<Centered>
{new Array(4).fill(0).map((_, i) => (
<TextInput
key={i}
placeholder={`${i}`}
placeholderTextColor="black"
style={{
width: "100%",
height: 50,
backgroundColor: randomColor(),
marginTop: 50,
}}
/>
))}
</Centered>
</KeyboardAwareScrollView>
);
} |
Describe the bug
I'm trying to replicate the
KeyboardAwareScrollView
behavior fromreact-native-keyboard-aware-scroll-view
. Using the KeyboardAwareScrollView found in/examples
, I noticed the scroll view scrolls more than it needs to:CleanShot.2023-06-06.at.09.27.54.mp4
Notice how once I press the input with the
scroll begins here
placeholder, it scrolls much further than it should. I'm trying to make the input align with my sticky action bar (it should be a fixed amount above the sticky bar).Code snippet
I used the code from your examples folder, with one modification:
I added an if/else branch that skips scrolling when the click wouldn't overlap with the keyboard + bottom offset. Now, I need to figure out the right interpolation math that causes the view to scroll only by the right/minimum amount.
note:
extraScrollHeight
is a prop, similar to yourBOTTOM_OFFSET
.Let me know if I can help with more details! I believe this would be a great addition to the component, since it enables a more seamless migration from
react-native-keyboard-aware-scroll-view
.The text was updated successfully, but these errors were encountered: