Skip to content

Fix scroll position on iOS#387

Merged
pinarol merged 16 commits intomasterfrom
fix/scroll-position
Dec 18, 2018
Merged

Fix scroll position on iOS#387
pinarol merged 16 commits intomasterfrom
fix/scroll-position

Conversation

@pinarol
Copy link
Copy Markdown
Contributor

@pinarol pinarol commented Dec 17, 2018

Fixes #197 partially

This change fixes inconsistent scroll behavior with input texts on iOS. Android behavior didn't change since it wasn't problematic.

iOS Before:
ezgif com-resize-2

After:

ezgif com-video-to-gif-2

Testing prerequisites

For WPiOS

  • Checkout the PRs branch to any arbitrary folder and cd .. to it
  • run yarn install, yarn start:reset
  • Open XCode WPiOS on the latest develop
  • Clean build folder on Xcode, and then run the app

For Android

  • open grade.properties at WordPress-Android folder
  • add wp.BUILD_GUTENBERG_FROM_SOURCE = true to grade.properties
  • checkout the PRs branch in the subrepo of WordPress-Android repo
  • cd to WordPress-Android/libs/gutenberg-mobile
  • run yarn install, yarn start:reset
  • yarn wpandroid on a separate terminal in the same directory

To Test

Test 1 - Empty post on WPiOS with return button

  • Open an empty post via WPiOS app
  • Start typing and press return button to create a new block
  • Repeat this until you add about 10 paragraph blocks
  • Verify that typed text input is viewable
  • Close the keyboard
  • Verify that scroll position goes back to normal

Test 2 - Add block with (+) button

  • Open some profiled post via WPiOS app
  • Add new text blocks with (+) button
  • Verify that recently added text input is viewable

Test 3 - Verify inner block buttons are working

  • Use up&down&trash buttons when keyboard is open or closed
  • Verify that they are working

Test 4 - Repeat tests for Android and make sure we didn't break anything, Android behavior shouldn't change with this PR.

@pinarol
Copy link
Copy Markdown
Contributor Author

pinarol commented Dec 17, 2018

cc @daniloercoli

@pinarol
Copy link
Copy Markdown
Contributor Author

pinarol commented Dec 17, 2018

I will work on travis failures but feel free to take a look @koke

@pinarol
Copy link
Copy Markdown
Contributor Author

pinarol commented Dec 17, 2018

we'll need to merge WordPress/gutenberg#12946 first

@pinarol
Copy link
Copy Markdown
Contributor Author

pinarol commented Dec 17, 2018

ready to review @etoledom @mzorz

extraScrollHeight={ extraScrollHeight }
extraHeight={ 0 }
innerRef={ ( ref ) => {
( this: any ).flatList = ref;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that all these ( this: any ) notation in this file are not necessary. I tried changing them to this. and it works fine and flow is still happy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this reference seems to be to the scrollView and not to the flatList? I might be a bit lost 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that all these ( this: any ) notation in this file are not necessary. I tried changing them to this. and it works fine and flow is still happy.

flow isn't happy to me :( that was the reason I used ( this: any ) in the first place, maybe you can have error if you run travis check in your local.

screen shot 2018-12-18 at 12 26 02

Also, this reference seems to be to the scrollView and not to the flatList? I might be a bit lost

right, I was using KeyboardAwareFlatList before and then changed it to KeyboardAwareScrollList but it looks like I forgot updating the name flatList. Will push a new commit for this 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed 401d698

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flow isn't happy to me :( that was the reason I used ( this: any ) in the first place, maybe you can have error if you run travis check in your local.

May that be because we are declaring variables "on the fly" in a stateless function component instead of "properly" declaring them in a class before accessing them?

Copy link
Copy Markdown
Contributor

@etoledom etoledom Dec 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But again, I'm not asking to make that change, just trying to understand the issue 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes right.. but we don't have a class here, KeyboardAwareFlatList is a function and we want these variable to be shared among these sub functions of KeyboardAwareFlatList.
so by using this we just insert the variables in the current context, not the ideal solution I agree.
I tried declaring KeyboardAwareFlatList as a React.PureCompoent/React.Compoent also but it causes unnecessary re-renders because extraData prop of FlatList changes and that change makes KeyboardAwareScrollView re-render.
Another solution would be declaring these variables in BlockManager and updating them via functions declared in the KeyboardAwareFlatList props, but I think that wouldn't be good since that variables are only needed here in iOS code :(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now. Sounds good to me! Let's ✅

@@ -0,0 +1,65 @@
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
/**
* @format
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpicking:
Can we have the import bellow those comments?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this here as a solution to flow error "Cannot resolve module react-native-keyboard-aware-scroll-view"
I think that happens because I added react-native-keyboard-aware-scroll-view to flowconfig ignore list because flow was trying to validate library source code as well. if there's another solution to this I can apply that happily I just couldn't find any.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that makes sense. In that case can we put a small comment explaining that? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hypest offered a new solution and I've pushed a new commit for it 4254072 It is so much better this way 🎉

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great solution! 😁

Copy link
Copy Markdown
Contributor

@etoledom etoledom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pinarol - This is looking really good! 🎉

Auto scrolling behaves nice and consistent, and I love that the inner toolbar remains visible.

I added a couple of non-blocking/non-important comments to the code but in general it looks super good.

I saw something weird with the scrolling indicator, and a very big extra bottom padding when the keyboard is showing. There's a gif showing it:

scrolling

I don't think this issue is blocking this PR since I don't see it really as something annoying for the users (as it was the auto-scrolling before). I would completely recommend you to merge this PR and just create an issue for that to be handled somewhen in the future (unless is really easy/fast to fix).

Great job! ✅

cc @mzorz - I haven't tested the Android WP App. In the Example app on android, autoscroll looks good but it doesn't show the inner toolbar. If that's how it was before, it would be great to match that behavior :)

extraScrollHeight={ extraScrollHeight }
extraHeight={ 0 }
innerRef={ ( ref ) => {
( this: any ).flatList = ref;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this reference seems to be to the scrollView and not to the flatList? I might be a bit lost 😅

Also replaced some spaces with tabs
@pinarol
Copy link
Copy Markdown
Contributor Author

pinarol commented Dec 18, 2018

@etoledom I've opened a bug for that issue, I don't think it is easily fixable, it is related with the inner mechanisms of KeyboardAwareScrollView.

@mzorz
Copy link
Copy Markdown
Contributor

mzorz commented Dec 18, 2018

Test 4 - Repeat tests for Android and make sure we didn't break anything, Android behavior shouldn't change with this PR.

I've been testing this for a while (smoke tests mostly), it seems to be OK as per my tests.

@pinarol
Copy link
Copy Markdown
Contributor Author

pinarol commented Dec 18, 2018

@etoledom @mzorz about showing the inner toolbar on Android: as far as I know KeyboardAvoidingView can't do it, I had tried KeyboardAwareScrollView on Android side also to achieve that but it behaves different, it first scrolls to the cursor and after some little time it scrolls again, this time for showing the inner toolbar. This is because Android already provides scrolling to the cursor position in the OS level(I guess) and the library just handles the extra scroll, this makes it look scrolling happen in 2 parts and doesn't look very good.

@pinarol pinarol merged commit 6dff0c7 into master Dec 18, 2018
@pinarol pinarol deleted the fix/scroll-position branch December 18, 2018 12:51
* @format
* @flow
*/
import { FlatList, KeyboardAvoidingView } from 'react-native';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pinarol . Late one...
We didn't use KeyboardAvoidingView from 'rect-native' but we had our abstract presentation of it in components/keyboard-avoiding-view.ios.js and components/keyboard-avoiding-view.android.js

That was introduced to fix the problem with toolbar visibility after orientation change in WPiOS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the heads up @marecar3 addressing that in #397

import BlockPicker from './block-picker';
import HTMLTextInput from '../components/html-text-input';
import BlockToolbar from './block-toolbar';
import KeyboardAvoidingView from '../components/keyboard-avoiding-view';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pinarol , here we are importing from our file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants