Skip to content

Commit d753eeb

Browse files
committed
perf: make sure keyboard ctx does not recreate on every render
1 parent 4c6b538 commit d753eeb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

package/src/components/KeyboardCompatibleView/KeyboardCompatibleView.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ export class KeyboardCompatibleView extends React.Component<
200200
this.unsetKeyboardListeners();
201201
}
202202

203+
keyboardContextValue = { dismissKeyboard: this.dismissKeyboard };
204+
203205
render() {
204206
const { behavior, children, contentContainerStyle, enabled, style, ...props } = this.props;
205207
const bottomHeight = enabled ? this.state.bottom : 0;
@@ -218,7 +220,7 @@ export class KeyboardCompatibleView extends React.Component<
218220
};
219221
}
220222
return (
221-
<KeyboardProvider value={{ dismissKeyboard: this.dismissKeyboard }}>
223+
<KeyboardProvider value={this.keyboardContextValue}>
222224
<View
223225
onLayout={this._onLayout}
224226
ref={this.viewRef}
@@ -232,7 +234,7 @@ export class KeyboardCompatibleView extends React.Component<
232234

233235
case 'position':
234236
return (
235-
<KeyboardProvider value={{ dismissKeyboard: this.dismissKeyboard }}>
237+
<KeyboardProvider value={this.keyboardContextValue}>
236238
<View onLayout={this._onLayout} ref={this.viewRef} style={style} {...props}>
237239
<View
238240
style={StyleSheet.compose(contentContainerStyle, {
@@ -247,7 +249,7 @@ export class KeyboardCompatibleView extends React.Component<
247249

248250
case 'padding':
249251
return (
250-
<KeyboardProvider value={{ dismissKeyboard: this.dismissKeyboard }}>
252+
<KeyboardProvider value={this.keyboardContextValue}>
251253
<View
252254
onLayout={this._onLayout}
253255
ref={this.viewRef}

0 commit comments

Comments
 (0)