Skip to content
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

iOS 14 TextInput jumping and auto-scrolling on tap #30207

Closed
nfjones87 opened this issue Oct 19, 2020 · 21 comments
Closed

iOS 14 TextInput jumping and auto-scrolling on tap #30207

nfjones87 opened this issue Oct 19, 2020 · 21 comments
Labels
Component: TextInput Related to the TextInput component. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@nfjones87
Copy link

nfjones87 commented Oct 19, 2020

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

Brand new build, nothing except the code below. Xcode version 12.0.1 iOS 14. RN 0.63.3. scrolling and tapping makes TextInput jump to random places. Happening on iPhone 11 Pro both simulator and device.

React Native version:

System:
OS: macOS 10.15.7
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 973.16 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.16.3 - /usr/local/bin/node
Yarn: Not Found
npm: 6.14.4 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
Android SDK: Not Found
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6392135
Xcode: 12.0.1/12A7300 - /usr/bin/xcodebuild
Languages:
Java: Not Found
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.3 => 0.63.3
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps To Reproduce

Simply have a basic TextInput with enough text to produce a vertical scrollbar, then scroll and tap.

Expected Results

The tap should place cursor at tapped position, and not autoscroll the TextInput to the wrong place.

Snack, code example, screenshot, or link to a repository:

export default class TextField extends Component {

   constructor(){
     super();
     this.state={textInput: ''}
   }

  handleChangeText = (textInput) => {
    this.setState({ textInput });
  }

    return (
        <View style={{flex: 1, backgroundColor: 'blue'}}>
           <TextInput 
            style={{marginTop: 100, height: 300, backgroundColor: 'white'}}
            value={this.state.textInput}
            multiline={true}
            onChangeText={this.handleChangeText}
          ></TextInput>     
        </View>
    )
}

scrollbugg

@react-native-bot react-native-bot added Component: TextInput Related to the TextInput component. Platform: iOS iOS applications. labels Oct 19, 2020
@nfjones87
Copy link
Author

nfjones87 commented Oct 20, 2020

Further information:

if I change the render to

render(){ return ( <ScrollView> <TextInput value={this.state.textInput} multiline={true} onChangeText={this.handleChangeText} /> </ScrollView> ); }

the issue is resolved on every phone i have tested EXCEPT the iPhone 11 Pro. (works with iPhone 11 and iPhone 11 Pro Max).

The issue on iPhone 11 Pro becomes that one cannot scroll the TextInput beyond the device's height unless I add a height to the TextInput. However, adding a height brings back the initial bug.

@safaiyeh
Copy link
Contributor

Hi @nfjones87 appreciate the investigation. Definitely odd behavior, what would cause the iPhone 11 Pro to have different behavior?

@nfjones87
Copy link
Author

Hi @safaiyeh , thanks for commenting. I really don't know what could cause the iPhone 11 Pro to have different behavior. I am simply toggling between different simulators, and it works on all except iPhone 11 pro. For whatever reason the iPhone 11 Pro needs the TextInput to have a set height or else it cannot scroll. However, setting a height produces the bug.

To clarify, the bug in the gif above is reproducible on all phones, however it can be fixed on all phones except the iPhone 11 Pro.

@nfjones87
Copy link
Author

Bump, anyone else experiencing this?

@RichardFevrier
Copy link

Sure @nfjones87 😌

@foloinfo
Copy link

I'm facing the same issue.
It happens when I specify the height of the TextInput.

I ended up avoiding this behavior by removing the height of TextInput and setting the height to the parent ScrollView (like in the comment above) and setting scrollEnabled to false

<ScrollView style={{ height: 300 }}>
  <TextInput
    scrollEnabled={false}
    style={{
      minHeight: 300,
    }}
  />
</ScrollView>

It still randomly scrolls when I tap the text but at least the cursor is pointed at where it should be so works a little better than setting the height directly, or maybe not.

@cenaHara
Copy link

hi @nfeignon Have you solved this problem yet?

@cenaHara
Copy link

I'm facing the same issue.
It happens when I specify the height of the TextInput.

I ended up avoiding this behavior by removing the height of TextInput and setting the height to the parent ScrollView (like in the comment above) and setting scrollEnabled to false

<ScrollView style={{ height: 300 }}>
  <TextInput
    scrollEnabled={false}
    style={{
      minHeight: 300,
    }}
  />
</ScrollView>

It still randomly scrolls when I tap the text but at least the cursor is pointed at where it should be so works a little better than setting the height directly, or maybe not.

Yes, you can see the position cursor but the scroll view cannot automatically scroll

@tnghia944
Copy link

It's an OS bug, I tried opening the app message from my phone, and it got the same

@YohanesFrangky
Copy link

hey, @nfjones87 have you fix this yet? i tried several open-source react native app, and try their textinput, and the bug is occured in all of them.

@tarouboy
Copy link

tarouboy commented Mar 3, 2021

Tried to rollback to 0.61.5 and problem persists on iOS 14+.

Tried to wrap the TextInput ( scrollEnabled=false ) with ScrollView, now I can tap on anywhere to edit, which is good.
However, I found two problems if wrapped by ScrollView:

  1. ScrollView won't scroll if you highlight the text and move upward/downward
  2. Pressing "Enter" on the keyboard won't scroll to the newline unless you type something ( it's very confusing )

@tkharuk
Copy link

tkharuk commented Mar 8, 2021

Experiencing the same issue.
Also, if I try to use "space" press to scroll select, Input goes wild and just blinks and flashes :(
This basically means users can not use scrollable editable content at all!

Any working workarounds to cover all platforms/versions?

@safaiyeh any plans from your side? I feel like this is a major one.

@YohanesFrangky
Copy link

Tried to rollback to 0.61.5 and problem persists on iOS 14+.

Tried to wrap the TextInput ( scrollEnabled=false ) with ScrollView, now I can tap on anywhere to edit, which is good.
However, I found two problems if wrapped by ScrollView:

  1. ScrollView won't scroll if you highlight the text and move upward/downward
  2. Pressing "Enter" on the keyboard won't scroll to the newline unless you type something ( it's very confusing )

yes I have tried that, but I got a problem with newline as well, so I can't use that approach

@efstathiosntonas
Copy link

efstathiosntonas commented Mar 11, 2021

Experiencing the same, here's an almost duplicate issue: #30748

@efstathiosntonas
Copy link

efstathiosntonas commented Mar 11, 2021

It seems that the animated:NO causes the issue, setting it to animated:YES fixes it partially.

- (void)setContentOffset:(CGPoint)contentOffset animated:(__unused BOOL)animated
{
// Turning off scroll animation.
// This fixes the problem also known as "flaky scrolling".
[super setContentOffset:contentOffset animated:NO];
}

Tested against iPhone 11 simulator and real iPhone XS.

But pressing space and moving up-down it's a bit jerky.

Update: Removing completely the above lines seems to improve up-down carret movement, I do not know what side effects this might cause though.

@tarouboy
Copy link

tarouboy commented Mar 12, 2021

Update: Removing completely the above lines seems to improve up-down carret movement. i do not know what side effects this might cause though.

Awesome! The jumpy behaviours seems to be fixed.

However, by removing the line completely it will stay at the current position and won't scroll to the caret position after entering something new at the end of the textInput.

Update:
For now it's my temp solution:

if (@available(iOS 14, *)) {
   // iOS 14 (or newer)
   [super setContentOffset:contentOffset animated:YES];
} else {
   // Turning off scroll animation.
   // This fixes the problem also known as "flaky scrolling".
   [super setContentOffset:contentOffset animated:NO];
}

@iKoru
Copy link

iKoru commented Apr 24, 2021

hello, @tarouboy and everyone.
I'm experiencing the same issue and want to fix it.
I tried @tarouboy 's solution and it seems the cursor is going to the right position but scroll effect is still the problem (goes to wrong place).
any idea to fix this?

@tarouboy
Copy link

hello, @tarouboy and everyone.
I'm experiencing the same issue and want to fix it.
I tried @tarouboy 's solution and it seems the cursor is going to the right position but scroll effect is still the problem (goes to wrong place).
any idea to fix this?

Mine is working fine. At least no more users are reporting the same issue.
Not sure about your case without further information.

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 23, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@fabOnReact
Copy link
Contributor

Do you still experience this issue?

I have four years of experience maintaining facebook/react-native and I specialize in the Text and TextInput components. I currently have 58 facebook/react-native PRs.

If you still experience this issue, I will prepare a patched release with the fix.

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: TextInput Related to the TextInput component. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests