-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Feature: Improvements to automaticallyAdjustKeyboardInsets
#37766
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
Closed
adamaveray
wants to merge
22
commits into
facebook:main
from
adamaveray:feature/automaticKeyboardInsetsImprovements
Closed
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6cd100a
Automatic keyboard insets improvements
isidoro98 24ce8b5
Prevent unintended scrolls on native navigation
isidoro98 7883315
Add bottomKeyboardOffset prop
isidoro98 42088b6
formatting
isidoro98 e2891a7
Update RCTScrollView.m
isidoro98 7422c3c
Merge branch 'main' into feature/automaticKeyboardInsetsImprovements
adamaveray 4b9e418
Add ScrollView keyboard insets example to RNTester
adamaveray ee6bbc3
Remove scroll view bottom keyboard offset property
adamaveray 12376c5
Add multiline inputs to keyboard insets tester
adamaveray 915be16
Add external text input to keyboard insets tester
adamaveray 145cc56
Improve scroll view keyboard insets text handling
adamaveray 9d7205f
Merge branch 'main' into feature/automaticKeyboardInsetsImprovements
adamaveray 08078a4
Prevent scrolling when focusing external textfield
adamaveray 62fc88a
Handle textfield focus in inverted scroll views
adamaveray 5e895f2
Support FlatLists in keyboard insets tester
adamaveray 8798130
Apply requested code format changes
adamaveray ca5ead8
Improve native text field keyboard offsetting
adamaveray 669dcff
Simplify calculating text input focus area
adamaveray cf08565
Document new scroll view property
adamaveray f643553
Add scroll view keyboard inset height test option
adamaveray b64e7a3
Merge branch 'main' into feature/automaticKeyboardInsetsImprovements
adamaveray c2eab2c
Rename iOS-specific example implementation
adamaveray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/react-native/React/Views/UIResponder+FirstResponder.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIResponder (FirstResponder) | ||
+(id)currentFirstResponder; | ||
@end |
24 changes: 24 additions & 0 deletions
24
packages/react-native/React/Views/UIResponder+FirstResponder.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "UIResponder+FirstResponder.h" | ||
|
||
static __weak id currentFirstResponder; | ||
|
||
@implementation UIResponder (FirstResponder) | ||
|
||
+(id)currentFirstResponder { | ||
currentFirstResponder = nil; | ||
[[UIApplication sharedApplication] sendAction:@selector(findFirstResponder:) to:nil from:nil forEvent:nil]; | ||
return currentFirstResponder; | ||
adamaveray marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
-(void)findFirstResponder:(id)sender { | ||
currentFirstResponder = self; | ||
} | ||
|
||
@end |
117 changes: 117 additions & 0 deletions
117
packages/rn-tester/js/examples/ScrollView/ScrollViewKeyboardInsetsExample.ios.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import * as React from 'react'; | ||
|
||
import { | ||
ScrollView, | ||
StyleSheet, | ||
Switch, | ||
Text, | ||
TextInput, | ||
View, | ||
} from 'react-native'; | ||
|
||
export function ScrollViewKeyboardInsetsExample() { | ||
const [automaticallyAdjustKeyboardInsets, setAutomaticallyAdjustKeyboardInsets] = React.useState(true); | ||
const [bottomKeyboardOffset, setBottomKeyboardOffset] = React.useState(0); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<View style={styles.controlRow}> | ||
<Text><Text style={styles.code}>automaticallyAdjustKeyboardInsets</Text> is {automaticallyAdjustKeyboardInsets + ''}</Text> | ||
<Switch | ||
onValueChange={v => setAutomaticallyAdjustKeyboardInsets(v)} | ||
value={automaticallyAdjustKeyboardInsets} | ||
style={styles.controlSwitch}/> | ||
</View> | ||
<View style={styles.controlRow}> | ||
<Text style={styles.code}>bottomKeyboardOffset</Text> | ||
<TextInput | ||
placeholder={bottomKeyboardOffset + ''} | ||
keyboardType={'numeric'} | ||
onChangeText={v => setBottomKeyboardOffset(parseInt(v || '0', 10))} | ||
style={styles.controlTextInput}/> | ||
</View> | ||
<ScrollView | ||
contentContainerStyle={[ | ||
styles.scrollViewContent, | ||
]} | ||
automaticallyAdjustKeyboardInsets={automaticallyAdjustKeyboardInsets} | ||
bottomKeyboardOffset={bottomKeyboardOffset} | ||
keyboardDismissMode={'interactive'}> | ||
{[...Array(20).keys()].map(item => ( | ||
<View key={item} style={styles.textInputRow}> | ||
<TextInput placeholder={item.toString()} style={styles.textInput}/> | ||
</View> | ||
))} | ||
</ScrollView> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'stretch', | ||
justifyContent: 'flex-start', | ||
}, | ||
scrollViewContent: { | ||
paddingVertical: 5, | ||
paddingHorizontal: 10, | ||
}, | ||
textInputRow: { | ||
borderWidth: 1, | ||
marginVertical: 8, | ||
borderColor: '#999', | ||
}, | ||
textInput: { | ||
width: '100%', | ||
backgroundColor: '#fff', | ||
fontSize: 24, | ||
padding: 8, | ||
}, | ||
controlRow: { | ||
padding: 10, | ||
alignItems: 'center', | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
backgroundColor: '#fff', | ||
borderTopWidth: 1, | ||
borderTopColor: '#ccc', | ||
borderBottomWidth: 1, | ||
borderBottomColor: '#ccc', | ||
}, | ||
controlSwitch: { | ||
}, | ||
controlTextInput: { | ||
flex: 1, | ||
paddingVertical: 10, | ||
paddingHorizontal: 10, | ||
marginVertical: -10, | ||
marginRight: -10, | ||
fontSize: 20, | ||
textAlign: 'right', | ||
}, | ||
code: { | ||
fontSize: 12, | ||
fontFamily: 'Courier', | ||
}, | ||
}); | ||
|
||
exports.title = 'ScrollViewKeyboardInsets'; | ||
exports.category = 'iOS'; | ||
exports.description = | ||
'ScrollView automaticallyAdjustKeyboardInsets adjusts keyboard insets when soft keyboard is activated.'; | ||
exports.examples = [ | ||
{ | ||
title: '<ScrollView> automaticallyAdjustKeyboardInsets Example', | ||
render: (): React.Node => <ScrollViewKeyboardInsetsExample/>, | ||
}, | ||
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.