Skip to content

Commit 0e736a8

Browse files
authored
Functional components
* Move to Functional components * Minor Fix: Android internet issue - debug mode
1 parent 4b4494d commit 0e736a8

File tree

12 files changed

+111
-131
lines changed

12 files changed

+111
-131
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ yarn android
149149
# react-native run-android --variant=Debug
150150
```
151151

152+
### Commands
153+
154+
| | Remark |
155+
|---|---|
156+
| `yarn start` | Starts metro bundler |
157+
| `yarn ios` | Starts iOS app. Start metro bundler first |
158+
| `yarn android` | Starts Android app. Start metro bundler and Android emulator first |
159+
| `yarn lint` | linting |
160+
| `yarn lint:fix` | tries to fix linting issues automatically |
161+
| `yarn build:android:debug` | Android debug build |
162+
| `yarn build:android:release` | Android release build |
163+
152164
### Cheat Sheet
153165

154166
#### iOS Launch Screen

android/app/src/debug/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools">
44

5+
<uses-permission android:name="android.permission.INTERNET" />
56
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
67

78
<application

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"react native navigation",
1010
"boilerplate"
1111
],
12-
"version": "0.4.5",
12+
"version": "0.4.6",
1313
"author": {
1414
"name": "Amit Mangal",
1515
"email": "[email protected]",

src/view/elements/buttons.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { TouchableOpacity, ViewStyle } from 'react-native';
33

44
import { GLOBAL } from '../styles/global';
5-
import { CText } from './custom';
5+
import { CTEXT } from './custom';
66

77
type Callback = () => any;
88
export interface Props {
@@ -12,15 +12,15 @@ export interface Props {
1212
}
1313

1414
/**
15-
* Default Button
15+
* Default Button for the application
1616
*/
17-
const BUTTON_DEFAULT = ({ title, onClick, style }: Props) => (
17+
const BUTTON_DEFAULT: React.FC<Props> = ({ title, onClick, style }: Props) => (
1818
<TouchableOpacity
1919
activeOpacity={GLOBAL.CTA.TouchableOpacity.default}
2020
style={[GLOBAL.CTA.Style.primary, GLOBAL.LAYOUT.shadow, style]}
2121
onPress={() => onClick()}
2222
>
23-
<CText style={GLOBAL.CTA.Style.primaryText}>{title}</CText>
23+
<CTEXT style={GLOBAL.CTA.Style.primaryText}>{title}</CTEXT>
2424
</TouchableOpacity>
2525
);
2626

src/view/elements/custom.tsx

+39-18
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
11
import * as React from 'react';
2-
import { Text, TextStyle } from 'react-native';
2+
import { StyleProp, Text, TextInput, TextStyle } from 'react-native';
33

44
import { GLOBAL } from '../styles/global';
5+
import { TYPOGRAPHY } from '../styles/typography';
56

6-
export interface Props {
7-
style: TextStyle;
7+
export interface TextProps {
8+
children: React.ReactElement | string;
9+
style?: StyleProp<TextStyle>;
810
}
911

10-
interface State {}
12+
export interface TextInputProps {
13+
style?: Object;
14+
disabled?: boolean;
15+
textInputRef?: any;
16+
placeholderTextColor?: string;
17+
}
1118

12-
class CText extends React.PureComponent<Props, State> {
13-
static defaultProps = {
14-
style: GLOBAL.TEXT.Default,
15-
};
19+
const CTEXT: React.FC<TextProps> = (props: TextProps) => (
20+
<Text style={[GLOBAL.TEXT.Default, props.style]}>
21+
{props.children}
22+
</Text>
23+
);
1624

17-
render() {
18-
const { style, children } = this.props;
25+
const CTEXTINPUT: React.FC<TextInputProps> = (props: TextInputProps) => {
26+
const {
27+
style,
28+
placeholderTextColor = TYPOGRAPHY.COLOR.Secondary,
29+
textInputRef,
30+
disabled = false,
31+
} = props;
32+
const [data, setData] = React.useState('');
1933

20-
return (
21-
<Text {...this.props} style={[GLOBAL.TEXT.Default, style]}>
22-
{children}
23-
</Text>
24-
);
25-
}
26-
}
34+
return (
35+
<TextInput
36+
ref={textInputRef}
37+
value={data}
38+
editable={!disabled}
39+
onChange={e => setData(e.nativeEvent.text)}
40+
placeholderTextColor={placeholderTextColor}
41+
underlineColorAndroid={'transparent'}
42+
{...props}
43+
style={[GLOBAL.TEXT_INPUT.Style.Default, style]}
44+
autoCorrect={false}
45+
/>
46+
);
47+
};
2748

28-
export { CText };
49+
export { CTEXT, CTEXTINPUT };

src/view/screens/drawer/Component.tsx

+8-24
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,14 @@ import * as React from 'react';
22
import { SafeAreaView } from 'react-native';
33

44
import styles from './styles';
5-
import { CText } from '../../elements/custom';
5+
import { CTEXT } from '../../elements/custom';
66

7-
export interface Props {
8-
name: string;
9-
}
7+
interface Props {}
108

11-
interface State {
12-
name: string;
13-
}
9+
const DRAWER: React.FC<Props> = () => (
10+
<SafeAreaView style={styles.container}>
11+
<CTEXT>{'Drawer Menu'}</CTEXT>
12+
</SafeAreaView>
13+
);
1414

15-
class Drawer extends React.PureComponent<Props, State> {
16-
constructor(props: Props) {
17-
super(props);
18-
}
19-
20-
componentDidMount() {}
21-
22-
render() {
23-
return (
24-
<SafeAreaView style={styles.container}>
25-
<CText>Drawer Menu</CText>
26-
</SafeAreaView>
27-
);
28-
}
29-
}
30-
31-
export default Drawer;
15+
export default DRAWER;

src/view/screens/dummy/Component.tsx

+9-25
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,18 @@ import * as React from 'react';
22
import { SafeAreaView } from 'react-native';
33

44
import styles from './styles';
5-
import { CText } from '../../elements/custom';
5+
import { CTEXT } from '../../elements/custom';
66

77
export interface Props {
88
dummyText: string;
9-
componentId: string;
9+
componentId?: string;
1010
}
1111

12-
interface State {
13-
name: string;
14-
}
15-
16-
class Home extends React.PureComponent<Props, State> {
17-
constructor(props: Props) {
18-
super(props);
19-
}
20-
21-
componentDidMount() {}
22-
23-
render() {
24-
const { dummyText } = this.props;
25-
26-
return (
27-
<SafeAreaView style={styles.container}>
28-
<CText>This Screen has been pushed over Home screen</CText>
29-
<CText>Prop passed: {dummyText}</CText>
30-
</SafeAreaView>
31-
);
32-
}
33-
}
12+
const DUMMY: React.FC<Props> = (props: Props) => (
13+
<SafeAreaView style={styles.container}>
14+
<CTEXT>{'This Screen has been pushed over Home screen'}</CTEXT>
15+
<CTEXT>{`Prop passed: ${props.dummyText}`}</CTEXT>
16+
</SafeAreaView>
17+
);
3418

35-
export default Home;
19+
export default DUMMY;

src/view/screens/home/Component.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Navigation } from 'react-native-navigation';
33
import { SafeAreaView, TouchableOpacity, Image } from 'react-native';
44

55
import styles from './styles';
6-
import { CText } from '../../elements/custom';
6+
import { CTEXT, CTEXTINPUT } from '../../elements/custom';
77
import router from '../../../navigators/router';
88
import { BUTTON_DEFAULT } from '../../elements/buttons';
99

@@ -59,8 +59,9 @@ class Home extends React.PureComponent<Props, State> {
5959
source={require('../../assets/images/burger-menu.png')}
6060
/>
6161
</TouchableOpacity>
62-
<CText>Home</CText>
63-
<CText>{name}</CText>
62+
<CTEXT>{'Home'}</CTEXT>
63+
<CTEXT>{name}</CTEXT>
64+
<CTEXTINPUT />
6465
<BUTTON_DEFAULT onClick={this.showPushScreen} title={'Push Screen'} style={styles.button} />
6566
</SafeAreaView>
6667
);

src/view/screens/settings/Component.tsx

+7-20
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,14 @@ import * as React from 'react';
22
import { SafeAreaView } from 'react-native';
33

44
import styles from './styles';
5-
import { CText } from '../../elements/custom';
5+
import { CTEXT } from '../../elements/custom';
66

77
export interface Props {}
88

9-
interface State {}
9+
const SETTINGS: React.FC<Props> = (props: Props) => (
10+
<SafeAreaView style={styles.container}>
11+
<CTEXT>{'Settings'}</CTEXT>
12+
</SafeAreaView>
13+
);
1014

11-
class Settings extends React.PureComponent<Props, State> {
12-
constructor(props: Props) {
13-
super(props);
14-
this.state = {};
15-
}
16-
17-
componentDidMount() {}
18-
19-
render() {
20-
return (
21-
<SafeAreaView style={styles.container}>
22-
<CText>Settings</CText>
23-
</SafeAreaView>
24-
);
25-
}
26-
}
27-
28-
export default Settings;
15+
export default SETTINGS;

src/view/screens/splash/Component.tsx

+13-21
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
import * as React from 'react';
22
import { View, Image, SafeAreaView } from 'react-native';
33

4-
import { tabbedNavigation } from '../../../navigators/navigation';
54
import styles from './styles';
5+
import { tabbedNavigation } from '../../../navigators/navigation';
66
import { BUTTON_DEFAULT } from '../../elements/buttons';
77

88
export interface Props {
99
splashLaunched: Function;
1010
}
1111

12-
interface State {}
12+
const SPLASH: React.FC<Props> = (props: Props) => {
1313

14-
class Splash extends React.PureComponent<Props, State> {
15-
constructor(props: Props) {
16-
super(props);
17-
this.state = {};
18-
}
19-
20-
componentDidMount() {
21-
const { splashLaunched } = this.props;
14+
React.useEffect(() => {
15+
const { splashLaunched } = props;
2216
splashLaunched();
23-
}
17+
}, []);
2418

25-
navigateToHome = () => {
19+
const navigateToHome = () => {
2620
tabbedNavigation();
27-
}
21+
};
2822

29-
render() {
30-
return (
31-
<SafeAreaView style={{ flex: 1 }}>
23+
return (
24+
<SafeAreaView style={{ flex: 1 }}>
3225
<View style={styles.container}>
3326
<Image
3427
style={styles.image}
@@ -41,12 +34,11 @@ class Splash extends React.PureComponent<Props, State> {
4134
/>
4235
<BUTTON_DEFAULT
4336
title="Continue To App"
44-
onClick={this.navigateToHome}
37+
onClick={navigateToHome}
4538
/>
4639
</View>
4740
</SafeAreaView>
48-
);
49-
}
50-
}
41+
);
42+
};
5143

52-
export default Splash;
44+
export default SPLASH;

src/view/styles/global.tsx

+12-14
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,17 @@ const LAYOUT = StyleSheet.create({
2626
const CTA = {
2727
Style: StyleSheet.create({
2828
primary: {
29-
flexDirection: 'row',
30-
alignItems: 'center',
31-
justifyContent: 'space-between',
3229
height: 48,
30+
borderWidth: 1,
31+
borderRadius: 10,
3332
paddingVertical: 8,
33+
alignItems: 'center',
3434
paddingHorizontal: 20,
35-
borderRadius: 10,
36-
borderWidth: 1,
37-
backgroundColor: TYPOGRAPHY.COLOR.Default,
35+
backgroundColor: TYPOGRAPHY.COLOR.Secondary,
3836
},
3937
primaryText: {
4038
fontSize: 16,
41-
color: TYPOGRAPHY.COLOR.Primary,
42-
textAlign: 'center',
39+
color: TYPOGRAPHY.COLOR.Default,
4340
},
4441
secondary: {
4542
flexDirection: 'row',
@@ -98,18 +95,19 @@ const TEXT = StyleSheet.create({
9895
const TEXT_INPUT = {
9996
Style: StyleSheet.create({
10097
Default: {
101-
fontFamily: TYPOGRAPHY.FONT.Primary,
102-
textAlign: 'left',
10398
fontSize: 12,
104-
borderWidth: 0.2,
99+
borderWidth: 1,
100+
borderRadius: 5,
101+
textAlign: 'left',
102+
fontFamily: TYPOGRAPHY.FONT.Primary,
105103
borderColor: TYPOGRAPHY.COLOR.Border,
106104
color: TYPOGRAPHY.COLOR.Primary,
107105
},
108106
Bold: {
109-
fontFamily: TYPOGRAPHY.FONT.Primary,
110-
textAlign: 'left',
111107
fontSize: 12,
112-
borderWidth: 0.2,
108+
textAlign: 'left',
109+
borderWidth: 1,
110+
fontFamily: TYPOGRAPHY.FONT.Primary,
113111
borderColor: TYPOGRAPHY.COLOR.Border,
114112
color: TYPOGRAPHY.COLOR.Primary,
115113
},

tslint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = {
8080
'static-method-regex': /^[a-z$][\w\d]+$/
8181
} // 23.1
8282
],
83-
'variable-name': [true, 'check-format'], // 23.2
83+
'variable-name': [true, 'check-format', 'allow-pascal-case'], // 23.2
8484
'class-name': true, // 23.3
8585
'no-this-assignment': [true, 'allow-destructuring'], // 23.5
8686
'import-name': true // 23.6

0 commit comments

Comments
 (0)