Skip to content

Typescript/keyboard #1449

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

Merged
merged 46 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d9bd00e
Keyboard index.js -> index.ts
mendyEdri Aug 2, 2021
574b94b
KeyboardAwareInsetsView.js -> KeyboardAwareInsetsView.tsx
mendyEdri Aug 2, 2021
645f89e
KeyboardTrackingView.android.js -> KeyboardTrackingView.android.tsx
mendyEdri Aug 2, 2021
8d030b3
KeyboardTrackingView.js -> KeyboardTrackingView.tsx
mendyEdri Aug 2, 2021
50d62d6
KeyboardTrackingView to work with ios and android
mendyEdri Aug 2, 2021
86a13db
lib/components index.js -> index.ts
mendyEdri Aug 2, 2021
e940d64
index.js -> index.ts
mendyEdri Aug 2, 2021
035c485
HighlighterOverlayView.js -> HighlighterOverlayView.tsx
mendyEdri Aug 2, 2021
3c60dee
HighlighterOverlayView.js -> HighlighterOverlayView.tsx
mendyEdri Aug 2, 2021
9fcd125
moved into own folder
mendyEdri Aug 2, 2021
b5a2d8d
CustomKeyboardView.android.js to CustomKeyboardView.android.tsx
mendyEdri Aug 2, 2021
be0fce0
CustomKeyboardView.ios.js -> CustomKeyboardView.ios.tsx
mendyEdri Aug 2, 2021
c21e54a
TextInputKeyboardManager in it's own folder
mendyEdri Aug 2, 2021
1832c9a
TextInputKeyboardManager.ios.js -> TextInputKeyboardManager.ios.tsx
mendyEdri Aug 2, 2021
1fd9344
TextInputKeyboardManager.android.js -> TextInputKeyboardManager.andro…
mendyEdri Aug 2, 2021
bb39962
TextInputKeyboardManager should be ts not tsx, fixed it
mendyEdri Aug 2, 2021
99e6e73
create index file for KeyboardInputKeyboardManager to work with diffe…
mendyEdri Aug 2, 2021
fff2c72
CustomKeyboardViewBase to tsx
mendyEdri Aug 2, 2021
356a512
KeyboardAccessoryView to tsx
mendyEdri Aug 2, 2021
2c834c6
files to typescript
mendyEdri Aug 2, 2021
80e4bed
SafeAreaSpacer to typescript
mendyEdri Aug 2, 2021
0c5568b
WheelPicker to tsx
mendyEdri Aug 2, 2021
a6f78f1
lib index fix ts error
mendyEdri Aug 3, 2021
07bef5a
CustomKeyboardViewBase to ts compatible
mendyEdri Aug 3, 2021
dce7d2e
CustomKeyboardView to ts compatible
mendyEdri Aug 3, 2021
e5dd04c
ts fix
mendyEdri Aug 3, 2021
3f64441
SafeAreaSpacerView ts fix
mendyEdri Aug 3, 2021
98c6ab9
WheelPicker index to ts
mendyEdri Aug 3, 2021
e03b507
CustomKeyboardView to ts
mendyEdri Aug 3, 2021
85f8982
SafeAreaInsetsManager ts compatible
mendyEdri Aug 3, 2021
c84fbd6
WheelPicketItem to ts compatible
mendyEdri Aug 3, 2021
85c5482
EventEmitterManager.js -> .ts
mendyEdri Aug 3, 2021
3025e47
KeyboardUtils to ts
mendyEdri Aug 3, 2021
aed1d87
Typings modifications
mendyEdri Aug 4, 2021
2cd5d26
added (and commented out) tscondig for build and dev env
mendyEdri Aug 5, 2021
5c9bc18
Some ts compatibility
mendyEdri Aug 5, 2021
ecea081
mock KeyboardTrackingViewTempManager
mendyEdri Aug 5, 2021
a656654
Merge branch 'master' into typescript/keyboard
mendyEdri Aug 12, 2021
30b25ac
export WheelPicker.Item
mendyEdri Aug 15, 2021
739603b
SafeAreaSpacerViewScreen.js -> tsx
mendyEdri Aug 15, 2021
999339c
SafeAreaSpacerViewScreen migrate to ts
mendyEdri Aug 15, 2021
21d4365
export all native components
mendyEdri Aug 15, 2021
6ef60c8
Small typescript fixes
mendyEdri Aug 15, 2021
dc7a196
Merge branch 'master' into typescript/keyboard
ethanshar Aug 18, 2021
e29f9e5
Merge branch 'master' into typescript/keyboard
ethanshar Aug 18, 2021
0117174
trigger build
ethanshar Aug 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,3 @@ class MyScreen extends Component {
}
}
```

Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React, {PureComponent} from 'react';
import {ScrollView, StyleSheet} from 'react-native';
import {Text, View, SafeAreaSpacerView} from 'react-native-ui-lib'; //eslint-disable-line
import {Text, View, SafeAreaSpacerView} from 'react-native-ui-lib';

export default class SafeAreaSpacerViewScreen extends PureComponent {

static options() {
return {
topBar: {
drawBehind: true,
visible: false,
},
visible: false
}
};
}

Expand All @@ -19,7 +18,7 @@ export default class SafeAreaSpacerViewScreen extends PureComponent {
<ScrollView contentContainerStyle={styles.scrollView}>
<View paddingH-25 center>
<Text text50 center>
{'When there are absolute-positioned view at the bottom and top,' +
{'When there are absolute-positioned view at the bottom and top,' +
'it is sometimes hard or impossible to change the layout and avoid it.'}
<Text red50> SafeAreaSpacerView </Text>
{'can be used as a BOTTOM or TOP spacer and will get the height of the safe area insets'}
Expand All @@ -43,16 +42,16 @@ const styles = StyleSheet.create({
scrollView: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
justifyContent: 'center'
},
topView: {
position: 'absolute',
top: 0,
left: 0,
left: 0
},
bottomView: {
position: 'absolute',
bottom: 0,
left: 0,
},
left: 0
}
});
16 changes: 8 additions & 8 deletions generatedTypes/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ export {default as Wizard, WizardProps, WizardStepProps, WizardStepStates, Wizar
export {default as ListItem, ListItemProps} from './components/listItem';
export {default as StateScreen, StateScreenProps} from './components/stateScreen';
export {default as LoaderScreen, LoaderScreenProps} from './components/loaderScreen';
export {
Keyboard,
SafeAreaSpacerView,
WheelPicker,
WheelPickerProps,
HighlighterOverlayView,
SafeAreaInsetsManager
} from '../lib/components';

/* All components with manual typings */
export {
Expand All @@ -105,8 +113,6 @@ export {
UIComponent,
forwardRef,
AvatarHelper,
WheelPicker,
WheelPickerProps,
Picker,
PickerItemValue,
PickerProps
Expand All @@ -116,11 +122,5 @@ export {
export const AnimatedImage;
export const AnimatedScanner;
export const DateTimePicker;
export const HighlighterOverlayView;
export const Keyboard;
export const KeyboardAwareListView;
export const KeyboardAwareScrollView;
export const SafeAreaInsetsManager;
export const SafeAreaSpacerView;
export const SelectableComponent;
export const TextField;
5 changes: 5 additions & 0 deletions jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock
global.__reanimatedWorkletInit = jest.fn();
jest.mock('react-native-gesture-handler', () => {});
jest.mock('@react-native-picker/picker', () => ({Picker: {Item: {}}}));
jest.mock('react-native', () => {
const reactNative = jest.requireActual('react-native');
reactNative.NativeModules.KeyboardTrackingViewTempManager = {};
return reactNative;
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
import React from 'react';
import PropTypes from 'prop-types';
import {requireNativeComponent, processColor, Platform, StyleSheet, Modal} from 'react-native';
import {requireNativeComponent, processColor, Platform, StyleSheet, Modal, ViewStyle} from 'react-native';

const NativeHighlighterView = requireNativeComponent('HighlighterView', null);
const NativeHighlighterView = requireNativeComponent('HighlighterView');
const DefaultOverlayColor = 'rgba(0, 0, 0, 0.5)';

const HighlighterOverlayView = (props) => {
type HighlightFrameType = {
x: number;
y: number;
width: number;
height: number;
}

type HighlightViewTagParams = {
padding: number | ViewStyle['padding'];
offset: Pick<HighlightFrameType, 'x' | 'y'>;
}

export type HighlighterOverlayViewProps = {
visible: boolean;
overlayColor?: string;
borderRadius?: number;
strokeColor?: string;
strokeWidth?: number;
onRequestClose?: () => void;
highlightFrame?: HighlightFrameType;
style?: ViewStyle;
highlightViewTag?: number | null;
children?: JSX.Element[] | JSX.Element;
highlightViewTagParams?: HighlightViewTagParams;
minimumRectSize?: Pick<HighlightFrameType, 'width' | 'height'>;
innerPadding?: number;
accessible?: boolean;
testID?: string;
};


const HighlighterOverlayView = (props: HighlighterOverlayViewProps) => {
const {
overlayColor,
borderRadius,
Expand All @@ -19,13 +49,15 @@ const HighlighterOverlayView = (props) => {
highlightViewTag,
highlightViewTagParams,
minimumRectSize,
innerPadding,
innerPadding
} = props;

let overlayColorToUse = overlayColor || DefaultOverlayColor;
let strokeColorToUse = strokeColor;
if (Platform.OS === 'android') {
// @ts-ignore
overlayColorToUse = processColor(overlayColorToUse);
// @ts-ignore
strokeColorToUse = processColor(strokeColorToUse);
}

Expand All @@ -34,9 +66,10 @@ const HighlighterOverlayView = (props) => {
visible={!!(visible)}
animationType={'fade'}
transparent
onRequestClose={() => onRequestClose && onRequestClose()}
onRequestClose={() => onRequestClose?.()}
>
<NativeHighlighterView
// @ts-ignore, this became private, not sure if I should remove it
highlightFrame={highlightFrame}
style={[style, {...StyleSheet.absoluteFillObject, backgroundColor: 'transparent'}]}
overlayColor={overlayColorToUse}
Expand All @@ -53,46 +86,5 @@ const HighlighterOverlayView = (props) => {
);
};

HighlighterOverlayView.propTypes = {
overlayColor: PropTypes.string,
borderRadius: PropTypes.number,
strokeColor: PropTypes.string,
strokeWidth: PropTypes.number,
visible: PropTypes.bool.isRequired,
onRequestClose: PropTypes.func,
highlightFrame: PropTypes.shape({
x: PropTypes.number,
y: PropTypes.number,
width: PropTypes.number,
height: PropTypes.number,
}),
style: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
highlightViewTag: PropTypes.number,
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
highlightViewTagParams: PropTypes.shape({
padding: PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({
top: PropTypes.number,
left: PropTypes.number,
bottom: PropTypes.number,
right: PropTypes.number}),
]),
offset: PropTypes.shape({
x: PropTypes.number,
y: PropTypes.number,
}),
}),
minimumRectSize: PropTypes.shape({
width: PropTypes.number,
height: PropTypes.number,
}),
innerPadding: PropTypes.number,
};

HighlighterOverlayView.displayName = 'IGNORE';

export default HighlighterOverlayView;
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import React from 'react';
import PropTypes from 'prop-types';
import {requireNativeComponent} from 'react-native';
import TextInputKeyboardManager from './TextInputKeyboardManager';
import KeyboardRegistry from './KeyboardRegistry';
import CustomKeyboardViewBase from './CustomKeyboardViewBase';
import TextInputKeyboardManager from '../TextInputKeyboardManager/TextInputKeyboardManager.android';
import KeyboardRegistry from '../KeyboardRegistry';
import CustomKeyboardViewBase, {CustomKeyboardViewBaseProps} from '../CustomKeyboardViewBase';

const CustomKeyboardViewNativeAndroid = requireNativeComponent('CustomKeyboardViewNativeTemp');

export default class CustomKeyboardView extends CustomKeyboardViewBase {
export default class CustomKeyboardView extends CustomKeyboardViewBase<CustomKeyboardViewBaseProps> {
static displayName = 'IGNORE';
static propTypes = {
initialProps: PropTypes.object,
component: PropTypes.string,
onItemSelected: PropTypes.func
};

async componentDidUpdate(prevProps) {
const {component} = this.props;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import PropTypes from 'prop-types';
import TextInputKeyboardManager from './TextInputKeyboardManager';
import KeyboardRegistry from './KeyboardRegistry';
import CustomKeyboardViewBase from './CustomKeyboardViewBase';
import TextInputKeyboardManager from './../TextInputKeyboardManager/TextInputKeyboardManager.ios';
import KeyboardRegistry from './../KeyboardRegistry';
import CustomKeyboardViewBase, {CustomKeyboardViewBaseProps} from './../CustomKeyboardViewBase';

export default class CustomKeyboardView extends CustomKeyboardViewBase {
export type CustomKeyboardViewProps = CustomKeyboardViewBaseProps & {
/**
* The reference to the actual text input (or the keyboard may not reset when instructed to, etc.)
*/
inputRef?: any;
useSafeArea?: boolean;
};

export default class CustomKeyboardView extends CustomKeyboardViewBase<CustomKeyboardViewProps> {
static displayName = 'IGNORE';
static propTypes = {
/**
* The reference to the actual text input (or the keyboard may not reset when instructed to, etc.)
*/
inputRef: PropTypes.object,
initialProps: PropTypes.object,
component: PropTypes.string,
onItemSelected: PropTypes.func,
useSafeArea: PropTypes.bool
};

static defaultProps = {
initialProps: {},
useSafeArea: true
};

registeredRequestShowKeyboard: boolean;
keyboardExpandedToggle: [any];

constructor(props) {
super(props);

Expand Down
16 changes: 16 additions & 0 deletions lib/components/Keyboard/KeyboardInput/CustomKeyboardView/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import {Platform} from 'react-native';
import {default as CustomKeyboardViewIOS, CustomKeyboardViewProps} from './CustomKeyboardView.ios';
import {default as CustomKeyboardViewAndroid} from './CustomKeyboardView.android';

const IsAndroid = Platform.OS === 'android';

const CustomKeyboardView = (props: CustomKeyboardViewProps) => {
const Container = IsAndroid ? CustomKeyboardViewAndroid : CustomKeyboardViewIOS;

return (
<Container {...props}/>
);
};

export default CustomKeyboardView;
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import {Component} from 'react';
import PropTypes from 'prop-types';
import React, {Component} from 'react';
import KeyboardRegistry from './KeyboardRegistry';
import {EventSubscription} from 'react-native';

export default class CustomKeyboardViewBase extends Component {
static propTypes = {
initialProps: PropTypes.object,
component: PropTypes.string,
onItemSelected: PropTypes.func
};
export type CustomKeyboardViewBaseProps = {
inputRef?: any;
initialProps?: any;
component?: string;
onItemSelected?: () => void;
onRequestShowKeyboard?: (keyboardId: string) => void;
children?: React.ReactChild | React.ReactChild[];
}

export default class CustomKeyboardViewBase<T extends CustomKeyboardViewBaseProps> extends Component<T> {

static defaultProps = {
initialProps: {}
};

registeredRequestShowKeyboard = false;
keyboardExpandedToggle: any;
keyboardEventListeners: [EventSubscription];

constructor(props) {
super(props);

const {component, onItemSelected} = props;
if (component) {
this.addOnItemSelectListener(onItemSelected, component);

this.registeredRequestShowKeyboard = false;
}

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

if (this.keyboardEventListeners) {
this.keyboardEventListeners.forEach(eventListener => eventListener.remove());
this.keyboardEventListeners.forEach((eventListener: EventSubscription) => eventListener.remove());
}

if (component) {
Expand Down
Loading