Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit 01ba66e

Browse files
committed
refactor: migrate codebase to typescript
1 parent b15e96d commit 01ba66e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1216
-1948
lines changed

.babelrc

-3
This file was deleted.

.circleci/config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ jobs:
3232
- persist_to_workspace:
3333
root: .
3434
paths: .
35-
lint-and-flow:
35+
lint-and-typecheck:
3636
<<: *defaults
3737
steps:
3838
- attach_workspace:
3939
at: ~/project
4040
- run: |
4141
yarn run lint
42-
yarn run flow
42+
yarn run typescript
4343
unit-tests:
4444
<<: *defaults
4545
steps:
@@ -55,6 +55,6 @@ workflows:
5555
build-and-test:
5656
jobs:
5757
- install-dependencies
58-
- lint-and-flow:
58+
- lint-and-typecheck:
5959
requires:
6060
- install-dependencies

.eslintignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules/
2-
flow-typed/
2+
3+
# generated by bob
4+
lib/

.eslintrc.json

-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,5 @@
55

66
"env": {
77
"react-native-globals/all": true
8-
},
9-
10-
"rules": {
11-
"flowtype/no-dupe-keys": "off",
12-
"flowtype/no-existential-type": "off"
138
}
149
}

.flowconfig

-127
This file was deleted.

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
# VSCode
99
.vscode/
10-
tsconfig.json
1110
jsconfig.json
1211

1312
# Xcode
@@ -48,3 +47,6 @@ buck-out/
4847
\.buckd/
4948
android/app/libs
5049
android/keystores/debug.keystore
50+
51+
# generated by bob
52+
lib/

.prettierrc

-4
This file was deleted.

.prettierrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"tabWidth": 2,
4+
"trailingComma": "es5",
5+
"useTabs": false
6+
}

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A cross-platform Tab View component for React Native.
1616
- Supports both top and bottom tab bars
1717
- Follows Material Design spec
1818
- Highly customizable
19-
- Fully typed with [Flow](https://flow.org/)
19+
- Fully typed with [TypeScript](https://typescriptlang.org)
2020

2121
## Demo
2222

@@ -567,10 +567,10 @@ On Android, enabling `removeClippedSubviews` can improve memory usage. This opti
567567

568568
While developing, you can run the [example app](/example/README.md) to test your changes.
569569

570-
Make sure your code passes Flow and ESLint. Run the following to verify:
570+
Make sure your code passes TypeScript and ESLint. Run the following to verify:
571571

572572
```sh
573-
yarn flow
573+
yarn typescript
574574
yarn lint
575575
```
576576

example/.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"plugins": [
66
["module-resolver", {
77
"alias": {
8-
"react-native-tab-view": "../src/index.js"
8+
"react-native-tab-view": "../src/index"
99
}
1010
}]
1111
]

example/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './src/App.tsx';

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "tabviewexample",
33
"version": "0.0.1",
44
"private": true,
5-
"main": "src/App.js",
5+
"main": "index.js",
66
"scripts": {
77
"start": "expo start",
88
"android": "expo android",

example/src/App.js example/src/App.tsx

+35-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* @flow */
2-
31
import { registerRootComponent, Asset, KeepAwake } from 'expo';
42
import * as React from 'react';
53
import {
@@ -21,16 +19,24 @@ import CustomTabBarExample from './CustomTabBarExample';
2119
import CoverflowExample from './CoverflowExample';
2220

2321
type State = {
24-
title: string,
25-
index: number,
26-
restoring: boolean,
22+
title: string;
23+
index: number;
24+
restoring: boolean;
25+
};
26+
27+
type ExampleComponentType = React.ComponentType<{}> & {
28+
title: string;
29+
tintColor?: string;
30+
backgroundColor?: string;
31+
statusBarStyle?: 'light-content' | 'dark-content';
32+
appbarElevation?: number;
2733
};
2834

2935
YellowBox.ignoreWarnings(['bind():']);
3036

3137
const PERSISTENCE_KEY = 'index_persistence';
3238

33-
const EXAMPLE_COMPONENTS = [
39+
const EXAMPLE_COMPONENTS: ExampleComponentType[] = [
3440
ScrollableTabBarExample,
3541
TabBarIconExample,
3642
CustomIndicatorExample,
@@ -47,7 +53,7 @@ export default class ExampleList extends React.Component<{}, State> {
4753

4854
componentDidMount() {
4955
if (process.env.NODE_ENV !== 'production') {
50-
this._restoreNavigationState();
56+
this.restoreNavigationState();
5157
}
5258

5359
[
@@ -62,21 +68,21 @@ export default class ExampleList extends React.Component<{}, State> {
6268
].map(image => Asset.fromModule(image).downloadAsync());
6369
}
6470

65-
_persistNavigationState = async (currentIndex: number) => {
71+
private persistNavigationState = async (currentIndex: number) => {
6672
if (process.env.NODE_ENV !== 'production') {
6773
await AsyncStorage.setItem(PERSISTENCE_KEY, JSON.stringify(currentIndex));
6874
}
6975
};
7076

71-
_restoreNavigationState = async () => {
77+
private restoreNavigationState = async () => {
7278
this.setState({
7379
restoring: true,
7480
});
7581

7682
const savedIndexString = await AsyncStorage.getItem(PERSISTENCE_KEY);
7783

7884
try {
79-
const savedIndex = JSON.parse(savedIndexString);
85+
const savedIndex = JSON.parse(savedIndexString || '');
8086

8187
if (
8288
Number.isFinite(savedIndex) &&
@@ -96,30 +102,28 @@ export default class ExampleList extends React.Component<{}, State> {
96102
});
97103
};
98104

99-
_handleNavigate = index => {
105+
private handleNavigate = (index: number) => {
100106
this.setState({
101107
index,
102108
});
103-
this._persistNavigationState(index);
109+
this.persistNavigationState(index);
104110
};
105111

106-
_handleNavigateBack = () => {
107-
this._handleNavigate(-1);
112+
private handleNavigateBack = () => {
113+
this.handleNavigate(-1);
108114
};
109115

110-
_renderItem = (component, i) => {
111-
return (
112-
<TouchableOpacity
113-
key={i}
114-
style={styles.touchable}
115-
onPress={() => this._handleNavigate(i)}
116-
>
117-
<Text style={styles.item}>
118-
{i + 1}. {component.title}
119-
</Text>
120-
</TouchableOpacity>
121-
);
122-
};
116+
private renderItem = (component: ExampleComponentType, i: number) => (
117+
<TouchableOpacity
118+
key={i}
119+
style={styles.touchable}
120+
onPress={() => this.handleNavigate(i)}
121+
>
122+
<Text style={styles.item}>
123+
{i + 1}. {component.title}
124+
</Text>
125+
</TouchableOpacity>
126+
);
123127

124128
render() {
125129
if (this.state.restoring) {
@@ -138,7 +142,7 @@ export default class ExampleList extends React.Component<{}, State> {
138142
? ExampleComponent.tintColor
139143
: 'white';
140144
const appbarElevation =
141-
ExampleComponent && Number.isFinite(ExampleComponent.appbarElevation)
145+
ExampleComponent && typeof ExampleComponent.appbarElevation === 'number'
142146
? ExampleComponent.appbarElevation
143147
: 4;
144148
const statusBarStyle =
@@ -151,10 +155,7 @@ export default class ExampleList extends React.Component<{}, State> {
151155
return (
152156
<View style={styles.container}>
153157
<StatusBar
154-
barStyle={
155-
/* $FlowFixMe */
156-
Platform.OS === 'ios' ? statusBarStyle : 'light-content'
157-
}
158+
barStyle={Platform.OS === 'ios' ? statusBarStyle : 'light-content'}
158159
/>
159160
<KeepAwake />
160161
<View
@@ -175,7 +176,7 @@ export default class ExampleList extends React.Component<{}, State> {
175176
{index > -1 ? (
176177
<TouchableOpacity
177178
style={styles.button}
178-
onPress={this._handleNavigateBack}
179+
onPress={this.handleNavigateBack}
179180
>
180181
<Ionicons
181182
name={
@@ -192,7 +193,7 @@ export default class ExampleList extends React.Component<{}, State> {
192193
{index > -1 ? <View style={styles.button} /> : null}
193194
</View>
194195
{index === -1 ? (
195-
<ScrollView>{EXAMPLE_COMPONENTS.map(this._renderItem)}</ScrollView>
196+
<ScrollView>{EXAMPLE_COMPONENTS.map(this.renderItem)}</ScrollView>
196197
) : ExampleComponent ? (
197198
<ExampleComponent />
198199
) : null}

0 commit comments

Comments
 (0)