Skip to content

Commit ab7611d

Browse files
authored
Feat/keyboard tracking view bottom view color (#2021)
* KeyboardTrackingView - add 'bottomViewColor' prop * fix master merge * Moving back to UIColor * fix * KeyboardAccessoryView - use others instead of passing each prop literally. * Updating lib version * fix api snippets * Fix example screen * KeyboardAccessotyView - removing duplicated props and extending selected KeyboardTrackingViewProps * KeyboardAccessoryView - 'iosScrollBehavior' prop deprecation (#2016) * KeyboardAccessoryView - iOSScrollBehavior prop deprecation * api fix * pr comments fixes * fix snippet * pr comments fixin'
1 parent 616f3b6 commit ab7611d

File tree

5 files changed

+42
-40
lines changed

5 files changed

+42
-40
lines changed

demo/src/screens/nativeComponentScreens/keyboardAccessory/demoKeyboards.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ function ImagesKeyboard() {
3737

3838
function CustomKeyboard() {
3939
return (
40-
<View flex padding-s4>
41-
<Text h3>Custom Keyboard</Text>
40+
<View flex bg-violet80 center>
41+
<Text h2>Custom Keyboard</Text>
4242
</View>
4343
);
4444
}

lib/components/Keyboard/KeyboardInput/KeyboardAccessoryView.tsx

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,7 @@ import KeyboardUtils from './utils/KeyboardUtils';
1616
const IsIOS = Platform.OS === 'ios';
1717
const IsAndroid = Platform.OS === 'android';
1818

19-
const IOS_SCROLL_BEHAVIORS = IsIOS
20-
? {
21-
NONE: NativeModules.KeyboardTrackingViewTempManager?.KeyboardTrackingScrollBehaviorNone,
22-
SCROLL_TO_BOTTOM_INVERTED_ONLY:
23-
NativeModules.KeyboardTrackingViewTempManager?.KeyboardTrackingScrollBehaviorScrollToBottomInvertedOnly,
24-
FIXED_OFFSET: NativeModules.KeyboardTrackingViewTempManager?.KeyboardTrackingScrollBehaviorFixedOffset
25-
}
26-
: {};
27-
28-
type kbTrackingViewProps = Pick<KeyboardTrackingViewProps, 'revealKeyboardInteractive' | 'manageScrollView' | 'requiresSameParentToManageScrollView' | 'allowHitsOutsideBounds' | 'addBottomView' | 'bottomViewColor' | 'useSafeArea' | 'usesBottomTabs'>;
19+
type kbTrackingViewProps = Pick<KeyboardTrackingViewProps, 'scrollBehavior' | 'revealKeyboardInteractive' | 'manageScrollView' | 'requiresSameParentToManageScrollView' | 'allowHitsOutsideBounds' | 'addBottomView' | 'bottomViewColor' | 'useSafeArea' | 'usesBottomTabs'>;
2920

3021
export type KeyboardAccessoryViewProps = kbTrackingViewProps & {
3122
/**
@@ -63,10 +54,9 @@ export type KeyboardAccessoryViewProps = kbTrackingViewProps & {
6354
*/
6455
onKeyboardResigned?: () => void;
6556
/**
66-
* iOS only.
67-
* The scrolling behavior, use KeyboardAccessoryView.iosScrollBehaviors.X where X is:
68-
* NONE, SCROLL_TO_BOTTOM_INVERTED_ONLY or FIXED_OFFSET
69-
* default: FIXED_OFFSET
57+
* @deprecated
58+
* Please use 'scrollBehavior' prop instead
59+
* The scrolling behavior (use KeyboardAccessoryView.scrollBehaviors.NONE | SCROLL_TO_BOTTOM_INVERTED_ONLY | FIXED_OFFSET)
7060
*/
7161
iOSScrollBehavior?: number;
7262
children?: React.ReactChild;
@@ -78,15 +68,19 @@ export type KeyboardAccessoryViewProps = kbTrackingViewProps & {
7868
* @gif: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/KeyboardAccessoryView/KeyboardAccessoryView.gif?raw=true
7969
*/
8070
class KeyboardAccessoryView extends Component<KeyboardAccessoryViewProps> {
81-
static iosScrollBehaviors = IOS_SCROLL_BEHAVIORS;
71+
/**
72+
* @deprecated Please use KeyboardAccessoryView.scrollBehaviors instead
73+
*/
74+
static iosScrollBehaviors = KeyboardTrackingView.scrollBehaviors; //TODO: remove on V7
75+
static scrollBehaviors = KeyboardTrackingView.scrollBehaviors;
8276

8377
static defaultProps = {
84-
iOSScrollBehavior: -1,
8578
revealKeyboardInteractive: false,
8679
manageScrollView: true,
8780
requiresSameParentToManageScrollView: false,
8881
addBottomView: false,
89-
allowHitsOutsideBounds: false
82+
allowHitsOutsideBounds: false,
83+
scrollBehavior: KeyboardTrackingView.scrollBehaviors.FIXED_OFFSET
9084
};
9185

9286
// TODO: fix
@@ -133,16 +127,6 @@ class KeyboardAccessoryView extends Component<KeyboardAccessoryViewProps> {
133127
return false;
134128
}
135129

136-
getIOSTrackingScrollBehavior() {
137-
const {iOSScrollBehavior} = this.props;
138-
139-
let scrollBehavior = iOSScrollBehavior;
140-
if (IsIOS && scrollBehavior === -1) {
141-
scrollBehavior = KeyboardAccessoryView.iosScrollBehaviors.FIXED_OFFSET;
142-
}
143-
return scrollBehavior;
144-
}
145-
146130
async getNativeProps() {
147131
if (this.trackingViewRef) {
148132
return await this.trackingViewRef.getNativeProps();
@@ -202,13 +186,15 @@ class KeyboardAccessoryView extends Component<KeyboardAccessoryViewProps> {
202186
onItemSelected,
203187
onRequestShowKeyboard,
204188
useSafeArea,
189+
scrollBehavior,
190+
iOSScrollBehavior,
205191
...others
206192
} = this.props;
207193

208194
return (
209195
<KeyboardTrackingView
210196
{...others}
211-
scrollBehavior={this.getIOSTrackingScrollBehavior()}
197+
scrollBehavior={IsIOS ? iOSScrollBehavior || scrollBehavior : undefined}
212198
ref={(r: any) => (this.trackingViewRef = r)}
213199
style={styles.trackingToolbarContainer}
214200
onLayout={this.onContainerComponentHeightChanged}

lib/components/Keyboard/KeyboardInput/keyboardAccessoryView.api.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@
4343
"name": "onKeyboardResigned",
4444
"type": "() => void",
4545
"description": "Callback that will be called once the keyboard has been closed"
46-
},
47-
{
48-
"name": "iOSScrollBehavior",
49-
"type": "number",
50-
"description": "The scrolling behavior, use KeyboardAccessoryView.iosScrollBehaviors.X where X is:\nNONE, SCROLL_TO_BOTTOM_INVERTED_ONLY or FIXED_OFFSET\niOS only.",
51-
"default": "FIXED_OFFSET"
5246
}
5347
],
5448
"snippet": [
@@ -58,5 +52,6 @@
5852
" kbComponent={$1}",
5953
" kbInitialProps={$2}",
6054
" onHeightChanged={this.onHeightChanged()}",
55+
" scrollBehavior={KeyboardAccessoryView.scrollBehaviors.NONE$3}",
6156
"/>"
6257
]}

lib/components/Keyboard/KeyboardTracking/KeyboardTrackingView/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import React, {forwardRef} from 'react';
2-
import {Platform, ViewStyle, ViewProps} from 'react-native';
2+
import {Platform, NativeModules, ViewStyle, ViewProps} from 'react-native';
33
import {default as KeyboardTrackingViewIOS} from './KeyboardTrackingView.ios';
44
import {default as KeyboardTrackingViewAndroid} from './KeyboardTrackingView.android';
55

66
const isAndroid = Platform.OS === 'android';
7+
const SCROLL_BEHAVIORS = {
8+
NONE: NativeModules.KeyboardTrackingViewTempManager?.KeyboardTrackingScrollBehaviorNone,
9+
SCROLL_TO_BOTTOM_INVERTED_ONLY:
10+
NativeModules.KeyboardTrackingViewTempManager?.KeyboardTrackingScrollBehaviorScrollToBottomInvertedOnly,
11+
FIXED_OFFSET: NativeModules.KeyboardTrackingViewTempManager?.KeyboardTrackingScrollBehaviorFixedOffset
12+
};
713

814
export type KeyboardTrackingViewProps = ViewProps & {
915
/**
@@ -46,6 +52,10 @@ export type KeyboardTrackingViewProps = ViewProps & {
4652
*/
4753
allowHitsOutsideBounds?: boolean;
4854
scrollToFocusedInput?: boolean;
55+
/**
56+
* iOS only.
57+
* The scrolling behavior (NONE | SCROLL_TO_BOTTOM_INVERTED_ONLY | FIXED_OFFSET)
58+
*/
4959
scrollBehavior?: number;
5060
/**
5161
* iOS only.
@@ -81,4 +91,6 @@ const KeyboardTrackingView = forwardRef(({children, ...others}: KeyboardTracking
8191
);
8292
});
8393

84-
export default KeyboardTrackingView;
94+
export default KeyboardTrackingView as (typeof KeyboardTrackingView & {scrollBehaviors: typeof SCROLL_BEHAVIORS});
95+
// @ts-expect-error
96+
KeyboardTrackingView.scrollBehaviors = SCROLL_BEHAVIORS;

lib/components/Keyboard/KeyboardTracking/KeyboardTrackingView/keyboardTrackingView.api.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@
1313
"type": "boolean",
1414
"description": "Enables tracking of the keyboard when it's dismissed interactively (false by default).\nWhy? When using an external keyboard (BT),\nyou still get the keyboard events and the view just hovers when you focus the input.\nAlso, if you're not using interactive style of dismissing the keyboard\n(or if you don't have an input inside this view) it doesn't make sense to track it anyway.\n(This is caused because of the usage of inputAccessory to be able to track the keyboard interactive change and it introduces this bug)"
1515
},
16-
{"name": "scrollToFocusedInput", "type": "boolean", "description": ""},
17-
{"name": "scrollBehavior", "type": "number", "description": ""},
16+
{
17+
"name": "scrollToFocusedInput",
18+
"type": "boolean",
19+
"description": "Should the scrollView scroll to the focused input"
20+
},
21+
{
22+
"name": "scrollBehavior",
23+
"type": "number",
24+
"description": "The scrolling behavior (use KeyboardTrackingView.scrollBehaviors.NONE | SCROLL_TO_BOTTOM_INVERTED_ONLY | FIXED_OFFSET)",
25+
"note": "iOS only"
26+
},
1827
{
1928
"name": "revealKeyboardInteractive",
2029
"type": "boolean",

0 commit comments

Comments
 (0)