Skip to content

Commit ae528a3

Browse files
authored
Revert "Revert "Typescript/keyboard (#1449)" (#1476)"
This reverts commit 2e59194.
1 parent dc586db commit ae528a3

33 files changed

+376
-308
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,3 @@ class MyScreen extends Component {
118118
}
119119
}
120120
```
121-

demo/src/screens/nativeComponentScreens/SafeAreaSpacerViewScreen.js renamed to demo/src/screens/nativeComponentScreens/SafeAreaSpacerViewScreen.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import React, {PureComponent} from 'react';
22
import {ScrollView, StyleSheet} from 'react-native';
3-
import {Text, View, SafeAreaSpacerView} from 'react-native-ui-lib'; //eslint-disable-line
3+
import {Text, View, SafeAreaSpacerView} from 'react-native-ui-lib';
44

55
export default class SafeAreaSpacerViewScreen extends PureComponent {
6-
76
static options() {
87
return {
98
topBar: {
109
drawBehind: true,
11-
visible: false,
12-
},
10+
visible: false
11+
}
1312
};
1413
}
1514

@@ -19,7 +18,7 @@ export default class SafeAreaSpacerViewScreen extends PureComponent {
1918
<ScrollView contentContainerStyle={styles.scrollView}>
2019
<View paddingH-25 center>
2120
<Text text50 center>
22-
{'When there are absolute-positioned view at the bottom and top,' +
21+
{'When there are absolute-positioned view at the bottom and top,' +
2322
'it is sometimes hard or impossible to change the layout and avoid it.'}
2423
<Text red50> SafeAreaSpacerView </Text>
2524
{'can be used as a BOTTOM or TOP spacer and will get the height of the safe area insets'}
@@ -43,16 +42,16 @@ const styles = StyleSheet.create({
4342
scrollView: {
4443
flex: 1,
4544
alignItems: 'center',
46-
justifyContent: 'center',
45+
justifyContent: 'center'
4746
},
4847
topView: {
4948
position: 'absolute',
5049
top: 0,
51-
left: 0,
50+
left: 0
5251
},
5352
bottomView: {
5453
position: 'absolute',
5554
bottom: 0,
56-
left: 0,
57-
},
55+
left: 0
56+
}
5857
});

generatedTypes/index.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ export {default as Wizard, WizardProps, WizardStepProps, WizardStepStates, Wizar
8585
export {default as ListItem, ListItemProps} from './components/listItem';
8686
export {default as StateScreen, StateScreenProps} from './components/stateScreen';
8787
export {default as LoaderScreen, LoaderScreenProps} from './components/loaderScreen';
88+
export {
89+
Keyboard,
90+
SafeAreaSpacerView,
91+
WheelPicker,
92+
WheelPickerProps,
93+
HighlighterOverlayView,
94+
SafeAreaInsetsManager
95+
} from '../lib/components';
8896

8997
/* All components with manual typings */
9098
export {
@@ -105,8 +113,6 @@ export {
105113
UIComponent,
106114
forwardRef,
107115
AvatarHelper,
108-
WheelPicker,
109-
WheelPickerProps,
110116
Picker,
111117
PickerItemValue,
112118
PickerProps
@@ -116,11 +122,5 @@ export {
116122
export const AnimatedImage;
117123
export const AnimatedScanner;
118124
export const DateTimePicker;
119-
export const HighlighterOverlayView;
120-
export const Keyboard;
121-
export const KeyboardAwareListView;
122-
export const KeyboardAwareScrollView;
123-
export const SafeAreaInsetsManager;
124-
export const SafeAreaSpacerView;
125125
export const SelectableComponent;
126126
export const TextField;

jest-setup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock
1010
global.__reanimatedWorkletInit = jest.fn();
1111
jest.mock('react-native-gesture-handler', () => {});
1212
jest.mock('@react-native-picker/picker', () => ({Picker: {Item: {}}}));
13+
jest.mock('react-native', () => {
14+
const reactNative = jest.requireActual('react-native');
15+
reactNative.NativeModules.KeyboardTrackingViewTempManager = {};
16+
return reactNative;
17+
});
Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
3-
import {requireNativeComponent, processColor, Platform, StyleSheet, Modal} from 'react-native';
2+
import {requireNativeComponent, processColor, Platform, StyleSheet, Modal, ViewStyle} from 'react-native';
43

5-
const NativeHighlighterView = requireNativeComponent('HighlighterView', null);
4+
const NativeHighlighterView = requireNativeComponent('HighlighterView');
65
const DefaultOverlayColor = 'rgba(0, 0, 0, 0.5)';
76

8-
const HighlighterOverlayView = (props) => {
7+
type HighlightFrameType = {
8+
x: number;
9+
y: number;
10+
width: number;
11+
height: number;
12+
}
13+
14+
type HighlightViewTagParams = {
15+
padding: number | ViewStyle['padding'];
16+
offset: Pick<HighlightFrameType, 'x' | 'y'>;
17+
}
18+
19+
export type HighlighterOverlayViewProps = {
20+
visible: boolean;
21+
overlayColor?: string;
22+
borderRadius?: number;
23+
strokeColor?: string;
24+
strokeWidth?: number;
25+
onRequestClose?: () => void;
26+
highlightFrame?: HighlightFrameType;
27+
style?: ViewStyle;
28+
highlightViewTag?: number | null;
29+
children?: JSX.Element[] | JSX.Element;
30+
highlightViewTagParams?: HighlightViewTagParams;
31+
minimumRectSize?: Pick<HighlightFrameType, 'width' | 'height'>;
32+
innerPadding?: number;
33+
accessible?: boolean;
34+
testID?: string;
35+
};
36+
37+
38+
const HighlighterOverlayView = (props: HighlighterOverlayViewProps) => {
939
const {
1040
overlayColor,
1141
borderRadius,
@@ -19,13 +49,15 @@ const HighlighterOverlayView = (props) => {
1949
highlightViewTag,
2050
highlightViewTagParams,
2151
minimumRectSize,
22-
innerPadding,
52+
innerPadding
2353
} = props;
2454

2555
let overlayColorToUse = overlayColor || DefaultOverlayColor;
2656
let strokeColorToUse = strokeColor;
2757
if (Platform.OS === 'android') {
58+
// @ts-ignore
2859
overlayColorToUse = processColor(overlayColorToUse);
60+
// @ts-ignore
2961
strokeColorToUse = processColor(strokeColorToUse);
3062
}
3163

@@ -34,9 +66,10 @@ const HighlighterOverlayView = (props) => {
3466
visible={!!(visible)}
3567
animationType={'fade'}
3668
transparent
37-
onRequestClose={() => onRequestClose && onRequestClose()}
69+
onRequestClose={() => onRequestClose?.()}
3870
>
3971
<NativeHighlighterView
72+
// @ts-ignore, this became private, not sure if I should remove it
4073
highlightFrame={highlightFrame}
4174
style={[style, {...StyleSheet.absoluteFillObject, backgroundColor: 'transparent'}]}
4275
overlayColor={overlayColorToUse}
@@ -53,46 +86,5 @@ const HighlighterOverlayView = (props) => {
5386
);
5487
};
5588

56-
HighlighterOverlayView.propTypes = {
57-
overlayColor: PropTypes.string,
58-
borderRadius: PropTypes.number,
59-
strokeColor: PropTypes.string,
60-
strokeWidth: PropTypes.number,
61-
visible: PropTypes.bool.isRequired,
62-
onRequestClose: PropTypes.func,
63-
highlightFrame: PropTypes.shape({
64-
x: PropTypes.number,
65-
y: PropTypes.number,
66-
width: PropTypes.number,
67-
height: PropTypes.number,
68-
}),
69-
style: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
70-
highlightViewTag: PropTypes.number,
71-
children: PropTypes.oneOfType([
72-
PropTypes.arrayOf(PropTypes.node),
73-
PropTypes.node,
74-
]),
75-
highlightViewTagParams: PropTypes.shape({
76-
padding: PropTypes.oneOfType([
77-
PropTypes.number,
78-
PropTypes.shape({
79-
top: PropTypes.number,
80-
left: PropTypes.number,
81-
bottom: PropTypes.number,
82-
right: PropTypes.number}),
83-
]),
84-
offset: PropTypes.shape({
85-
x: PropTypes.number,
86-
y: PropTypes.number,
87-
}),
88-
}),
89-
minimumRectSize: PropTypes.shape({
90-
width: PropTypes.number,
91-
height: PropTypes.number,
92-
}),
93-
innerPadding: PropTypes.number,
94-
};
95-
9689
HighlighterOverlayView.displayName = 'IGNORE';
97-
9890
export default HighlighterOverlayView;

lib/components/Keyboard/KeyboardInput/CustomKeyboardView.android.js renamed to lib/components/Keyboard/KeyboardInput/CustomKeyboardView/CustomKeyboardView.android.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import {requireNativeComponent} from 'react-native';
4-
import TextInputKeyboardManager from './TextInputKeyboardManager';
5-
import KeyboardRegistry from './KeyboardRegistry';
6-
import CustomKeyboardViewBase from './CustomKeyboardViewBase';
3+
import TextInputKeyboardManager from '../TextInputKeyboardManager/TextInputKeyboardManager.android';
4+
import KeyboardRegistry from '../KeyboardRegistry';
5+
import CustomKeyboardViewBase, {CustomKeyboardViewBaseProps} from '../CustomKeyboardViewBase';
76

87
const CustomKeyboardViewNativeAndroid = requireNativeComponent('CustomKeyboardViewNativeTemp');
98

10-
export default class CustomKeyboardView extends CustomKeyboardViewBase {
9+
export default class CustomKeyboardView extends CustomKeyboardViewBase<CustomKeyboardViewBaseProps> {
1110
static displayName = 'IGNORE';
12-
static propTypes = {
13-
initialProps: PropTypes.object,
14-
component: PropTypes.string,
15-
onItemSelected: PropTypes.func
16-
};
1711

1812
async componentDidUpdate(prevProps) {
1913
const {component} = this.props;

lib/components/Keyboard/KeyboardInput/CustomKeyboardView.ios.js renamed to lib/components/Keyboard/KeyboardInput/CustomKeyboardView/CustomKeyboardView.ios.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
import PropTypes from 'prop-types';
2-
import TextInputKeyboardManager from './TextInputKeyboardManager';
3-
import KeyboardRegistry from './KeyboardRegistry';
4-
import CustomKeyboardViewBase from './CustomKeyboardViewBase';
1+
import TextInputKeyboardManager from './../TextInputKeyboardManager/TextInputKeyboardManager.ios';
2+
import KeyboardRegistry from './../KeyboardRegistry';
3+
import CustomKeyboardViewBase, {CustomKeyboardViewBaseProps} from './../CustomKeyboardViewBase';
54

6-
export default class CustomKeyboardView extends CustomKeyboardViewBase {
5+
export type CustomKeyboardViewProps = CustomKeyboardViewBaseProps & {
6+
/**
7+
* The reference to the actual text input (or the keyboard may not reset when instructed to, etc.)
8+
*/
9+
inputRef?: any;
10+
useSafeArea?: boolean;
11+
};
12+
13+
export default class CustomKeyboardView extends CustomKeyboardViewBase<CustomKeyboardViewProps> {
714
static displayName = 'IGNORE';
8-
static propTypes = {
9-
/**
10-
* The reference to the actual text input (or the keyboard may not reset when instructed to, etc.)
11-
*/
12-
inputRef: PropTypes.object,
13-
initialProps: PropTypes.object,
14-
component: PropTypes.string,
15-
onItemSelected: PropTypes.func,
16-
useSafeArea: PropTypes.bool
17-
};
1815

1916
static defaultProps = {
17+
initialProps: {},
2018
useSafeArea: true
2119
};
2220

21+
registeredRequestShowKeyboard: boolean;
22+
keyboardExpandedToggle: [any];
23+
2324
constructor(props) {
2425
super(props);
2526

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import {Platform} from 'react-native';
3+
import {default as CustomKeyboardViewIOS, CustomKeyboardViewProps} from './CustomKeyboardView.ios';
4+
import {default as CustomKeyboardViewAndroid} from './CustomKeyboardView.android';
5+
6+
const IsAndroid = Platform.OS === 'android';
7+
8+
const CustomKeyboardView = (props: CustomKeyboardViewProps) => {
9+
const Container = IsAndroid ? CustomKeyboardViewAndroid : CustomKeyboardViewIOS;
10+
11+
return (
12+
<Container {...props}/>
13+
);
14+
};
15+
16+
export default CustomKeyboardView;

lib/components/Keyboard/KeyboardInput/CustomKeyboardViewBase.js renamed to lib/components/Keyboard/KeyboardInput/CustomKeyboardViewBase.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
import {Component} from 'react';
2-
import PropTypes from 'prop-types';
1+
import React, {Component} from 'react';
32
import KeyboardRegistry from './KeyboardRegistry';
3+
import {EventSubscription} from 'react-native';
44

5-
export default class CustomKeyboardViewBase extends Component {
6-
static propTypes = {
7-
initialProps: PropTypes.object,
8-
component: PropTypes.string,
9-
onItemSelected: PropTypes.func
10-
};
5+
export type CustomKeyboardViewBaseProps = {
6+
inputRef?: any;
7+
initialProps?: any;
8+
component?: string;
9+
onItemSelected?: () => void;
10+
onRequestShowKeyboard?: (keyboardId: string) => void;
11+
children?: React.ReactChild | React.ReactChild[];
12+
}
1113

14+
export default class CustomKeyboardViewBase<T extends CustomKeyboardViewBaseProps> extends Component<T> {
15+
1216
static defaultProps = {
1317
initialProps: {}
1418
};
1519

20+
registeredRequestShowKeyboard = false;
21+
keyboardExpandedToggle: any;
22+
keyboardEventListeners: [EventSubscription];
23+
1624
constructor(props) {
1725
super(props);
1826

1927
const {component, onItemSelected} = props;
2028
if (component) {
2129
this.addOnItemSelectListener(onItemSelected, component);
22-
23-
this.registeredRequestShowKeyboard = false;
2430
}
2531

2632
this.keyboardExpandedToggle = {};
@@ -35,7 +41,7 @@ export default class CustomKeyboardViewBase extends Component {
3541
KeyboardRegistry.removeListeners('onRequestShowKeyboard');
3642

3743
if (this.keyboardEventListeners) {
38-
this.keyboardEventListeners.forEach(eventListener => eventListener.remove());
44+
this.keyboardEventListeners.forEach((eventListener: EventSubscription) => eventListener.remove());
3945
}
4046

4147
if (component) {

0 commit comments

Comments
 (0)