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

Touchable/Button in Modal dismisses keyboard on Touch if Modal's parent is a ScrollView without keyboardShouldPersistTaps #28871

Closed
divonelnc opened this issue May 11, 2020 · 5 comments
Labels
API: Keyboard Component: Button Component: Modal Component: ScrollView Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@divonelnc
Copy link

divonelnc commented May 11, 2020

Description

If you have a TextInput and a Touchable (or Button) inside a Modal, inside a ScrollView that doesn't have keyboardShouldPersistTaps on always or handled, touching the Touchable will dismiss the keyboard.

React Native version:

System:
OS: Windows 10 10.0.18362
CPU: (4) x64 Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz
Memory: 3.15 GB / 15.96 GB
Binaries:
Node: 10.15.3 - E:\nodejs\node.EXE
Yarn: 1.22.0 - E:\Yarn\bin\yarn.CMD
npm: 6.14.5 - E:\nodejs\npm.CMD
SDKs:
Android SDK:
API Levels: 29
Build Tools: 29.0.0, 29.0.3
System Images: android-29 | Google APIs Intel x86 Atom
npmPackages:
react: 16.9.0 => 16.9.0
react-native: https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz => 0.61.4
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7

Steps To Reproduce

  1. Create a ScrollView without keyboardShouldPersistTaps set
  2. Add a Modal inside this view, containing a Button or Touchable and a TextInput
  3. focus on the TextInput to show the keyboard
  4. Tap the Touchable/Button
  5. Keyboard gets dismissed

Expected Results

Tapping the touchable should not dismiss the Keyboard. The ancestor ScrollView should not cause the Keyboard to get dismissed, as the Modal itself doesn't have a scrollView.

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

function TestComp() {
	const [showingModal, setshowingModal] = React.useState(false);
	return (
		<ScrollView contentContainerStyle={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
			<Button title={"Show modal"} onPress={() => setshowingModal(true)} />

			<Modal visible={showingModal} onRequestClose={() => setshowingModal(false)}>
				<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
					<View style={{ flex: 1, marginTop: 22 }}>
						<Button title={"hide modal"} onPress={() => setshowingModal(false)} />
					</View>
					<TextInput autoFocus />
				</View>
			</Modal>
		</ScrollView>
	);
}
@divonelnc divonelnc changed the title Touchable* in Modal dismisses keyboard if Modal parent is a ScrollView without keyboardShouldPersistTaps Touchable/Button in Modal dismisses keyboard on Touch if Modal parent is a ScrollView without keyboardShouldPersistTaps May 11, 2020
@divonelnc divonelnc changed the title Touchable/Button in Modal dismisses keyboard on Touch if Modal parent is a ScrollView without keyboardShouldPersistTaps Touchable/Button in Modal dismisses keyboard on Touch if Modal's parent is a ScrollView without keyboardShouldPersistTaps May 12, 2020
@SiroSong
Copy link

SiroSong commented May 15, 2020

same issue,when i use input element embed Modal in Scrollview,keyboard seem to be stop the callback on Madal, when I first touched screen the keyboard would hide, but Madal did nothing, only when I second touched, callback on Modal worked.
I tried, Flatlist same trouble yet.
Why??

@mysport12
Copy link
Contributor

I ran into the same issue, but was able to work around it by adding keyboardShouldPersistTaps='handled' to the Modal's parent ScrollView as noted.

@stale
Copy link

stale bot commented Oct 4, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Oct 4, 2020
@stale
Copy link

stale bot commented Oct 12, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Oct 12, 2020
@cristianoccazinsp
Copy link
Contributor

Is there any way to have the scrollview of the parent use keyboardShouldPersistTaps={'never'} but the modal itself behave has "handled" ? Why does the parent scrollview interfere with the modal? Nonsense.

@facebook facebook locked as resolved and limited conversation to collaborators Oct 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API: Keyboard Component: Button Component: Modal Component: ScrollView Needs: Triage 🔍 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

5 participants