Skip to content

Commit 73e06a1

Browse files
committed
add setLayoutIfNeededOnUpdate to fix problem with safearea
1 parent e811336 commit 73e06a1

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ if (Platform.OS === 'ios') {
8181
KeyboardManager.setEnable(true);
8282
KeyboardManager.setEnableDebugging(false);
8383
KeyboardManager.setKeyboardDistanceFromTextField(10);
84+
KeyboardManager.setLayoutIfNeededOnUpdate(true);
8485
KeyboardManager.setEnableAutoToolbar(true);
8586
KeyboardManager.setToolbarDoneBarButtonItemText("Done");
8687
KeyboardManager.setToolbarManageBehaviourBy("subviews"); // "subviews" | "tag" | "position"

Sample/App.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import KeyboardManager, { PreviousNextView } from 'react-native-keyboard-manager
3838
KeyboardManager.setEnable(true);
3939
KeyboardManager.setEnableDebugging(true);
4040
KeyboardManager.setKeyboardDistanceFromTextField(30);
41+
KeyboardManager.setLayoutIfNeededOnUpdate(true);
4142
KeyboardManager.setEnableAutoToolbar(true);
4243
KeyboardManager.setToolbarDoneBarButtonItemText("Done");
4344
KeyboardManager.setToolbarManageBehaviourBy("subviews"); // "subviews" | "tag" | "position"
@@ -120,28 +121,28 @@ class App extends Component {
120121
return (
121122
<View style={{ flex: 1 }}>
122123
<SafeAreaView style={{ flex: 1 }}>
123-
{/* To try with Modal, uncomment the two following lines. */}
124-
{/* <Modal visible={true}> */}
125-
{/* <PreviousNextView style={{ flex: 1 }}> */}
124+
{/* To try with Modal, uncomment the two following lines. */}
125+
{/* <Modal visible={true}> */}
126+
{/* <PreviousNextView style={{ flex: 1 }}> */}
126127

127-
{/* ScrollView is not required, but may be needed in some cases. */}
128-
<ScrollView>
128+
{/* ScrollView is not required, but may be needed in some cases. */}
129+
<ScrollView>
129130

130-
<View style={{ alignItems: "center" }}>
131+
<View style={{ alignItems: "center" }}>
131132
<Text style={{ marginTop: 10, textAlign: "center" }}>React-Native Keyboard Manager</Text>
132-
<View style={{ marginTop: 10, flexDirection: "row", alignItems: "center" }}>
133-
<Text>Enable/Disable </Text>
134-
<Switch onValueChange={this.onEnableDisable}
135-
value={this.state.enableDisable} />
133+
<View style={{ marginTop: 10, flexDirection: "row", alignItems: "center" }}>
134+
<Text>Enable/Disable </Text>
135+
<Switch onValueChange={this.onEnableDisable}
136+
value={this.state.enableDisable} />
137+
</View>
136138
</View>
137-
</View>
138139

139-
<View>{inputs}</View>
140+
<View>{inputs}</View>
140141

141-
</ScrollView>
142+
</ScrollView>
142143

143-
{/* </PreviousNextView> */}
144-
{/* </Modal> */}
144+
{/* </PreviousNextView> */}
145+
{/* </Modal> */}
145146
</SafeAreaView>
146147
</View>
147148
)

ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ - (instancetype)init
5454
if (self) {
5555
Swizzle([RCTBaseTextInputView class], @selector(setDefaultInputAccessoryView_backup), @selector(setDefaultInputAccessoryView));
5656
Swizzle([RCTBaseTextInputView class], @selector(setDefaultInputAccessoryView), @selector(setDefaultInputAccessoryView_avoid));
57+
58+
// set LayoutIfNeededOnUpdate to YES to prevent problems with SateArea
59+
// https://github.com/hackiftekhar/IQKeyboardManager/issues/1687#issuecomment-721618667
60+
[[IQKeyboardManager shared] setLayoutIfNeededOnUpdate:YES];
5761
}
5862
return self;
5963
}
@@ -108,6 +112,11 @@ - (dispatch_queue_t)methodQueue
108112
[[IQKeyboardManager shared] setKeyboardDistanceFromTextField:distance];
109113
}
110114

115+
RCT_EXPORT_METHOD(setLayoutIfNeededOnUpdate: (BOOL) enabled) {
116+
if (debugging) RCTLogInfo(@"KeyboardManager.setLayoutIfNeededOnUpdate: %d", enabled);
117+
[[IQKeyboardManager shared] setLayoutIfNeededOnUpdate:enabled];
118+
}
119+
111120
// UIToolbar handling
112121

113122
RCT_EXPORT_METHOD(setToolbarPreviousNextButtonEnable: (BOOL) enabled) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-keyboard-manager",
3-
"version": "6.5.4-2",
3+
"version": "6.5.4-3",
44
"description": "Library that allows to prevent issues of keyboard sliding up and cover on React-Native iOS projects. ⚛",
55
"private": false,
66
"types": "index.d.ts",

0 commit comments

Comments
 (0)