-
Notifications
You must be signed in to change notification settings - Fork 15
/
App.tsx
176 lines (167 loc) · 4.14 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import React from 'react';
import {
StyleSheet,
Text,
Pressable,
SafeAreaView,
FlatList,
View,
} from 'react-native';
import SimpleStepper from 'react-native-simple-stepper';
const reactNativeFavicon = {
uri: 'https://reactnative.dev/docs/assets/favicon.png',
};
const steppers = [
{
name: 'Default stepper',
description: 'Default everything.',
stepper: <SimpleStepper />,
},
{
name: 'Wraps stepper',
description:
'It shall cycle around dictated by minimum (0) and maximum (10) values. showText enabled to help demonstrate it',
stepper: <SimpleStepper wraps showText />,
},
{
name: 'Decimal stepper',
description: 'initialValue and stepValue set to 0.99.',
stepper: <SimpleStepper showText initialValue={0.99} stepValue={0.99} />,
},
{
name: 'Remote stepper',
description: 'incrementImage and decrementImage set to remote images.',
stepper: (
<SimpleStepper
incrementImage={reactNativeFavicon}
decrementImage={reactNativeFavicon}
valueChanged={(value: number) => {
console.log('[onValueChanged] value: ', value);
}}
/>
),
},
{
name: 'Action stepper',
description:
'onMin, onMax, onIncrement and onDecrement functions are used to log value.',
stepper: (
<SimpleStepper
onMin={(value: number) => {
console.log('[onMin] value: ', value);
}}
onMax={(value: any) => {
console.log('[onMax] value: ', value);
}}
onIncrement={(value: any) => {
console.log('[onIncrement] value: ', value);
}}
onDecrement={(value: any) => {
console.log('[onDecrement] value: ', value);
}}
/>
),
},
{
name: 'Red stepper',
description:
'textPosition is center by default. useColor and showText are enabled. color set to red.',
stepper: <SimpleStepper useColor showText color={'red'} />,
},
{
name: 'Green stepper',
description:
'textPosition set to right. useColor and showText are enabled. color set to green.',
stepper: (
<SimpleStepper useColor showText textPosition={'right'} color={'green'} />
),
},
{
name: 'Blue stepper',
description:
'textPosition set to left. useColor and showText are enabled. color set to blue.',
stepper: (
<SimpleStepper useColor showText textPosition={'left'} color={'blue'} />
),
},
];
type StepperExample = {
item: {
name: string;
description: string;
stepper: JSX.Element;
};
index: number;
};
function App(): React.JSX.Element {
const _renderItem = (example: StepperExample) => {
const {name, description, stepper} = example.item;
return (
<Pressable style={styles.button}>
<View style={styles.content}>
<Text style={styles.name}>{name}</Text>
<Text style={styles.description}>{description}</Text>
</View>
{stepper}
</Pressable>
);
};
const _renderSeparator = () => {
return <View style={styles.separator} />;
};
const _renderHeader = () => {
return (
<View style={styles.header}>
<Text style={styles.title}>{'Stepper examples'}</Text>
</View>
);
};
return (
<SafeAreaView>
<FlatList
data={steppers}
initialNumToRender={steppers.length}
renderItem={_renderItem}
keyExtractor={(item, index) => `${index}`}
ItemSeparatorComponent={_renderSeparator}
ListHeaderComponent={_renderHeader}
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
button: {
flexDirection: 'row',
alignItems: 'center',
padding: 8,
},
content: {
flex: 1,
marginHorizontal: 8,
},
name: {
fontSize: 16,
fontWeight: '500',
marginVertical: 4,
color: 'black',
},
description: {
fontSize: 14,
color: 'black',
},
separator: {
backgroundColor: 'black',
height: StyleSheet.hairlineWidth,
},
header: {
padding: 8,
borderBottomColor: 'black',
borderBottomWidth: StyleSheet.hairlineWidth,
},
title: {
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});
export default App;