Skip to content

Commit 6399b14

Browse files
TheBuggedYRNymabdallah
authored andcommitted
[MOB-11585] Migrate Example to TypeScript (#893)
1 parent 4f67017 commit 6399b14

File tree

12 files changed

+113
-39
lines changed

12 files changed

+113
-39
lines changed

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"devDependencies": {
2222
"@babel/core": "^7.15.8",
2323
"@babel/runtime": "^7.15.4",
24+
"@types/react-native-vector-icons": "^6.4.13",
2425
"babel-jest": "^27.2.5",
2526
"detox": "^19.8.4",
2627
"jest": "^27.2.5",

example/src/App.js renamed to example/src/App.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ import { createTabBarIcon } from './components/TabBarIcon';
88
import { HomeScreen } from './screens/HomeScreen';
99
import { SettingsScreen } from './screens/SettingsScreen';
1010

11-
const Tab = createBottomTabNavigator();
11+
export type RootStackParamList = {
12+
Home: undefined;
13+
Settings: undefined;
14+
};
1215

13-
export function App() {
16+
const Tab = createBottomTabNavigator<RootStackParamList>();
17+
18+
export const App: React.FC = () => {
1419
useEffect(() => {
1520
Instabug.init({
1621
token: '2c63627b9923e10eee2c8abf92e6925f',
@@ -29,4 +34,4 @@ export function App() {
2934
</Tab.Navigator>
3035
</NavigationContainer>
3136
);
32-
}
37+
};

example/src/components/Button.js renamed to example/src/components/Button.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from 'react';
2-
import { StyleSheet, Text, TouchableOpacity } from 'react-native';
2+
import { StyleSheet, Text, TouchableOpacity, TouchableOpacityProps } from 'react-native';
33

4-
export function Button({ children, onPress }) {
4+
export const Button: React.FC<TouchableOpacityProps> = ({ children, ...props }) => {
55
return (
6-
<TouchableOpacity style={styles.button} onPress={onPress}>
6+
<TouchableOpacity style={styles.button} {...props}>
77
<Text style={styles.text}>{children}</Text>
88
</TouchableOpacity>
99
);
10-
}
10+
};
1111

1212
const styles = StyleSheet.create({
1313
text: {

example/src/components/ColorButton.js renamed to example/src/components/ColorButton.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { StyleSheet, TouchableOpacity } from 'react-native';
33

44
import Icon from 'react-native-vector-icons/Ionicons';
55

6-
export function ColorButton({ color, checked = false, onPress }) {
6+
interface ColorButtonProps {
7+
checked: boolean;
8+
color: string;
9+
onPress: (color: string) => void;
10+
}
11+
12+
export const ColorButton: React.FC<ColorButtonProps> = ({ color, checked = false, onPress }) => {
713
return (
814
<TouchableOpacity
915
accessibilityRole="checkbox"
@@ -14,7 +20,7 @@ export function ColorButton({ color, checked = false, onPress }) {
1420
{checked && <Icon name="checkmark-sharp" color="white" size={30} accessible={false} />}
1521
</TouchableOpacity>
1622
);
17-
}
23+
};
1824

1925
const styles = StyleSheet.create({
2026
button: {

example/src/components/Screen.js renamed to example/src/components/Screen.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import React from 'react';
1+
import React, { PropsWithChildren } from 'react';
22
import { ScrollView, StyleSheet, View } from 'react-native';
33

4-
export function Screen({ children }) {
4+
export const Screen: React.FC<PropsWithChildren> = ({ children }) => {
55
return (
66
<View testID="welcome" style={styles.container}>
77
<ScrollView contentContainerStyle={styles.contentContainer}>{children}</ScrollView>
88
</View>
99
);
10-
}
10+
};
1111

1212
const styles = StyleSheet.create({
1313
container: {

example/src/components/Section.js renamed to example/src/components/Section.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import React from 'react';
1+
import React, { PropsWithChildren } from 'react';
22
import { StyleSheet, Text, View } from 'react-native';
33

4-
export function Section({ title, children }) {
4+
interface SectionProps extends PropsWithChildren {
5+
title: string;
6+
}
7+
8+
export const Section: React.FC<SectionProps> = ({ title, children }) => {
59
return (
610
<View style={styles.section}>
711
<Text style={styles.title}>{title}</Text>
8-
912
{children}
1013
</View>
1114
);
12-
}
15+
};
1316

1417
const styles = StyleSheet.create({
1518
section: {

example/src/components/TabBarIcon.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

example/src/components/TabBarIcon.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
3+
import type { BottomTabNavigationOptions } from '@react-navigation/bottom-tabs';
4+
import type { RouteProp } from '@react-navigation/native';
5+
import Icon from 'react-native-vector-icons/Ionicons';
6+
7+
import type { RootStackParamList } from '../App';
8+
9+
interface TabBarIconProps {
10+
route: RouteProp<RootStackParamList>;
11+
focused: boolean;
12+
color: string;
13+
size: number;
14+
}
15+
16+
export const createTabBarIcon = (
17+
route: RouteProp<RootStackParamList>,
18+
): BottomTabNavigationOptions['tabBarIcon'] => {
19+
return (props) => <TabBarIcon {...props} route={route} />;
20+
};
21+
22+
export const TabBarIcon: React.FC<TabBarIconProps> = ({ route, focused, color, size }) => {
23+
let name = route.name.toLowerCase();
24+
if (!focused) {
25+
name += '-outline';
26+
}
27+
28+
return <Icon name={name} color={color} size={size} />;
29+
};

example/src/screens/HomeScreen.js renamed to example/src/screens/HomeScreen.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function HomeScreen() {
2121

2222
const showFeatureRequests = () => FeatureRequests.show();
2323

24-
const sendBugReport = () => BugReporting.show(BugReporting.reportType.bug);
24+
const sendBugReport = () => BugReporting.show(BugReporting.reportType.bug, []);
2525

2626
const sendCrashReport = () => {
2727
try {
@@ -37,7 +37,7 @@ export function HomeScreen() {
3737
const sendFeedback = () =>
3838
BugReporting.show(BugReporting.reportType.feedback, [BugReporting.option.emailFieldHidden]);
3939

40-
const startNewConversation = () => BugReporting.show(BugReporting.reportType.question);
40+
const startNewConversation = () => BugReporting.show(BugReporting.reportType.question, []);
4141

4242
const showUnreadMessagesCount = () =>
4343
Replies.getUnreadRepliesCount((count) => Alert.alert('Messages: ' + count));

example/src/screens/SettingsScreen.js renamed to example/src/screens/SettingsScreen.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ export function SettingsScreen() {
2424

2525
const isLightTheme = theme === Instabug.colorTheme.light;
2626

27-
const toggleColorTheme = (isLight) => {
27+
const toggleColorTheme = (isLight: boolean) => {
2828
const newTheme = isLight ? Instabug.colorTheme.light : Instabug.colorTheme.dark;
2929
Instabug.setColorTheme(newTheme);
3030
setTheme(newTheme);
3131
};
3232

33-
const setPrimaryColor = (newColor) => {
33+
const setPrimaryColor = (newColor: string) => {
3434
Instabug.setPrimaryColor(newColor);
3535
setColor(newColor);
3636
};
3737

38-
const changeInvocationEvent = (invocationEvent) =>
38+
const changeInvocationEvent = (invocationEvent: Instabug.invocationEvent) =>
3939
BugReporting.setInvocationEvents([invocationEvent]);
4040

4141
return (

0 commit comments

Comments
 (0)