Skip to content

Commit e4e8446

Browse files
feat: Migrate to typescript (#63)
1 parent 3ac2c25 commit e4e8446

23 files changed

+198
-103
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ local.properties
4040
node_modules/
4141
npm-debug.log
4242
yarn-error.log
43+
*.tsbuildinfo
4344

4445
# fastlane
4546
#

App.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'react-native-gesture-handler';
2+
import React, { Component } from 'react';
3+
import { AppRegistry } from 'react-native';
4+
import Router from './router/Router';
5+
6+
export default class VodQAReactNative extends Component {
7+
render(): React.JSX.Element {
8+
return <Router />;
9+
}
10+
}
11+
12+
AppRegistry.registerComponent('VodQAReactNative', () => VodQAReactNative);

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# VodQAReactNative
22

3-
A React Native mobile application demonstrating various UI interactions and gestures, rebuilt on React Native 0.73.6.
3+
A React Native mobile application demonstrating various UI interactions and gestures.
44

55
## Features
66

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import LoginScreen from '../screens/LoginScreen';
1010
const mockNavigation = {
1111
navigate: jest.fn(),
1212
goBack: jest.fn(),
13-
};
13+
} as any;
1414

1515
describe('LoginScreen', () => {
1616
beforeEach(() => {
1717
jest.clearAllMocks();
1818
});
1919

2020
it('renders without crashing', async () => {
21-
let tree;
21+
let tree: ReactTestRenderer.ReactTestRenderer | undefined;
2222
await act(async () => {
2323
tree = ReactTestRenderer.create(
2424
React.createElement(LoginScreen, { navigation: mockNavigation }),
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ jest.mock('../screens/NativeView', () => mockScreen());
3737
jest.mock('../screens/WheelPicker', () => mockScreen());
3838

3939
describe('Router', () => {
40-
let Router;
41-
let ReactTestRenderer;
42-
let React;
43-
let act;
40+
let Router: React.ComponentType;
41+
let ReactTestRenderer: any;
42+
let React: any;
43+
let act: any;
4444

4545
beforeAll(async () => {
4646
// Import Router after mocks are set up
@@ -51,7 +51,7 @@ describe('Router', () => {
5151
});
5252

5353
it('renders without crashing', async () => {
54-
let tree;
54+
let tree: any;
5555
await act(async () => {
5656
tree = ReactTestRenderer.create(React.createElement(Router));
5757
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import SamplesListScreen from '../screens/SamplesListScreen';
1010
const mockNavigation = {
1111
navigate: jest.fn(),
1212
goBack: jest.fn(),
13-
};
13+
} as any;
1414

1515
describe('SamplesListScreen', () => {
1616
beforeEach(() => {
1717
jest.clearAllMocks();
1818
});
1919

2020
it('renders without crashing', async () => {
21-
let tree;
21+
let tree: ReactTestRenderer.ReactTestRenderer | undefined;
2222
await act(async () => {
2323
tree = ReactTestRenderer.create(
2424
React.createElement(SamplesListScreen, { navigation: mockNavigation }),

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ react {
3737
// bundleAssetName = "MyApplication.android.bundle"
3838
//
3939
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
40-
// entryFile = file("../js/MyApplication.android.js")
40+
// entryFile = file("../../index.js")
4141
//
4242
// A list of extra flags to pass to the 'bundle' commands.
4343
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
import { StyleSheet, Platform } from 'react-native';
1+
import {
2+
StyleSheet,
3+
Platform,
4+
ViewStyle,
5+
TextStyle,
6+
ImageStyle,
7+
} from 'react-native';
28

3-
export function create(styles) {
4-
const platformStyles = {};
9+
type Style = ViewStyle | TextStyle | ImageStyle;
10+
11+
interface PlatformStyle {
12+
ios?: Style;
13+
android?: Style;
14+
[key: string]: any;
15+
}
16+
17+
interface Styles {
18+
[key: string]: PlatformStyle | Style;
19+
}
20+
21+
export function create(styles: Styles): any {
22+
const platformStyles: { [key: string]: Style } = {};
523
Object.keys(styles).forEach(name => {
6-
let { ios, android, ...style } = { ...styles[name] };
24+
let { ios, android, ...style } = { ...styles[name] } as any;
725
if (ios && Platform.OS === 'ios') {
826
style = { ...style, ...ios };
927
}

index.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
import 'react-native-gesture-handler';
2-
import React, { Component } from 'react';
3-
import { AppRegistry } from 'react-native';
4-
import Router from './router/Router';
1+
import App from './App.tsx';
52

6-
export default class VodQAReactNative extends Component {
7-
render() {
8-
return <Router />;
9-
}
10-
}
11-
12-
AppRegistry.registerComponent('VodQAReactNative', () => VodQAReactNative);
3+
export default App;

router/Router.js renamed to router/Router.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Routes from './Routes';
1818

1919
const Stack = createStackNavigator();
2020

21-
function Router() {
21+
function Router(): React.JSX.Element {
2222
return (
2323
<NavigationContainer>
2424
<Stack.Navigator
@@ -98,4 +98,5 @@ function Router() {
9898
</NavigationContainer>
9999
);
100100
}
101+
101102
export default Router;

0 commit comments

Comments
 (0)