-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
On Android, TextInputs within a position: absolute
view that's inside another view with onLayout can't be focused
#29308
Comments
I also encountered a similar problem. When the view is absolutely positioned, internal events cannot be triggered, but positioning can be triggered to cover subsequent events, such as Scrollview's scroll event. I think it may be due to hierarchy, but I can't make a mask like thing on the outer layer of the positioned view, because it will affect the layout of peers. I hope someone can help me. So your problem here, I think, is due to the absolute positioning. |
Touchables inside absolutely positioned View not working either |
Interesting bug, I was able to see this in the snack. I've seen some PRs and issues relating to hierarchy of view elements. I wonder if one of those would help (don't have a list of them handy on me right now) |
Same problem here. It works just fine on iOS but Android. |
from quick troubleshooting I notice that react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java Line 202 in fb974ce
I troubleshooted something similar #27333 (comment) and #27333 (comment) but in this case I think this is an actual bug. Also many information about this issue are included in #29911 #25441 #28694 Most of the time this can be fixed using react-native-gesture-handler component, but in this case it is not possible. I further investigate. |
Same problem here. TextInput does not get focused and the buttons aren't pressable on Android if it's inside an absolutely positioned View and it happens even without onLayout. Eg.
|
https://reactnative.dev/docs/touchablewithoutfeedback#hitslop
The parent is absolute positioned and has computed CLICK TO OPEN - CODE SNIPPET
class RewriteExampleInvalidCharacters extends React.Component {
render() {
return (
<View
nativeID="1"
style={{backgroundColor: 'yellow', height: 150}}
onLayout={() => {}}>
<View
nativeID="2"
style={{
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
zIndex: 2,
height: 100,
backgroundColor: 'red',
}}>
<TextInput nativeID="3" defaultValue="Try selecting this text" />
</View>
</View>
);
}
} CLICK TO OPEN - REACTANDROID JAVA METHOD ANALYSIS
In the example included in this issue react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java Lines 178 to 180 in 0060b5d
CLICK TO OPEN TESTS RESULTS - VIDEO CLICKING ON TEXTINPUT
CLICK TO OPEN - VIDEO EXPLANATION OF THE REASON
In the example below the react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java Lines 178 to 180 in 0060b5d
<View
nativeID="1"
style={{backgroundColor: 'yellow'}}
onLayout={() => {}}>
<View
nativeID="2"
style={{
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
zIndex: 2,
// height: 100,
backgroundColor: 'red',
}}>
<TextInput nativeID="3" defaultValue="Try selecting this text" />
</View>
</View>
In the example below the react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java Lines 178 to 180 in 0060b5d
<View
nativeID="1"
style={{backgroundColor: 'yellow', height: 150}}
onLayout={() => {}}>
<View
nativeID="2"
style={{
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
zIndex: 2,
// height: 100,
backgroundColor: 'red',
}}>
<TextInput nativeID="3" defaultValue="Try selecting this text" />
</View>
</View>
Related #25441 #28694 #27333 (comment) |
I'm facing the same issue here |
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. |
Hey guys I've fixed mine and this might fix yours! The thing that is happening when you position a view as absolute, the view automatically being placed at the bottom of Z index placement. So basically react native uses the html concepts about z Index. We cannot focus the textinputs and touchables within the absolute view because when we click it we are clicking the View which positioned in the same place the absolute view is at. So we need to elevate the absolute view by putting "zIndex: 1" or "zIndex: 1000", depending on how many elements your absolute view overlapped. So basically this not a bug, it's just a plain old html concept we missed. |
The root cause of this issue is #37181 I included some workarounds in that issue too |
Please provide all the information requested. Issues that do not follow this format are likely to stall.
Description
Given a hierarchy of views:
<View>
with onLayout prop<View>
that hasposition: 'absolute'
styleText inside the TextInput can't be selected. Removing the first view's onLayout prop or the second view's
position: 'absolute'
will allow text in the TextInput to be selected.React Native version:
v0.62.2
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
Expected Results
Describe what you expected to happen.
The text should be selected
Snack, code example, screenshot, or link to a repository:
https://snack.expo.io/@harrytravelchime/react-native-issue-29308
The text was updated successfully, but these errors were encountered: