TabViewAnimated causes keyboard dismissal when rendered on Android
Expected behaviour
Rendering ViewPagerAndroid shouldn't cause keyboard dismissal.
Actual behaviour
As soon as ViewPagerAndroid is rendered, it causes keyboard dismissal.
Code sample, screenshots
<TabViewAnimated
style={styles.container}
navigationState={this.state}
renderScene={this.renderScene}
renderHeader={this.renderHeader}
onIndexChange={this.handleChangeTab}
useNativeDriver
/>
which renders the following on Android
<ViewPagerAndroid
key={navigationState.routes.length}
keyboardDismissMode="on-drag"
initialPage={initialPage}
scrollEnabled={swipeEnabled !== false}
onPageScroll={this._handlePageScroll}
onPageScrollStateChanged={this._handlePageScrollStateChanged}
onPageSelected={this._handlePageSelected}
style={styles.container}
ref={this._setRef}
>
{content}
</ViewPagerAndroid>`
What have you tried
Updating the keyboardDismissMode to none does the trick for me. This problem doesn't exist on iOS, so it seems to be a problem with either ViewPagerAndroid or TabViewPagerAndroid.
I can see clear use cases for "on-drag" and "none" modes for the keyboard dismissal prop. In our case, we have an aggregated search view which renders results in a tab view. The tabs render once we have results, but the user may want to change the search query, so dismissing the keyboard is problematic, and the behavior is different on iOS.
Passing the prop down from TabViewAnimated seems like a decent solution since the behavior could vary by use case. If there is actually a bug here and the keyboard would only dismiss when the view is dragged, then making the prop configurable seems like a non-issue.
Feel free to send a PR which adds support for configuring keyboardDismissMode for TabViewPagerAndroid and TabViewPagerScroll. Unused props in TabViewAnimated are passed to the underlying pager, so you don't need to change anything there.
👍
Submitted a PR to address this issue: https://github.com/react-native-community/react-native-tab-view/pull/453
Hi, setting keyboardDismissMode to none doesn't dismiss the keyboard upon rendering ViewPagerAndroid. But how do I dismiss the keyboard on drag in this case? The keyboard is always up even when I switch to another tab.
What I've tried:
onPositionChange={Keyboard.dismiss} (on version 0.0.70)
But onPositionChange is called upon load, which dismisses the keyboard.
Any workaround for this? Thanks.
I think it'll be great to have a third mode which uses the best of both on-drag and none. I'm manually setting the keyboardDismissMode to on-drag in componentDidUpdate for now.
@ananyachandra14 did you solve this issue? I am hardcoding keyboardDismissMode to 'none' inside the TabViewPagerAndroid but its not working
@impradeepsaini Hi, what's your use case?
When you set keyboardDismissMode to none, and land on a tab with an auto-focussed TextInput, the keyboard should stay open.
Dismissing the keyboard on drag in this case is a separate issue. You'll have to set keyboardDismissMode to on-drag in TabViewPagerAndroid's componentDidUpdate.