-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(example): separating components from the app file
- Loading branch information
1 parent
3dda804
commit 8fdbf79
Showing
4 changed files
with
128 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { StyleSheet, Text, TouchableOpacity } from 'react-native'; | ||
|
||
interface OptionButtonProps { | ||
title: string; | ||
onPress(): void; | ||
} | ||
|
||
export function OptionButton({ title, onPress }: OptionButtonProps) { | ||
return ( | ||
<TouchableOpacity onPress={onPress} style={styles.button}> | ||
<Text style={styles.buttonText}>{title}</Text> | ||
</TouchableOpacity> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
button: { | ||
backgroundColor: 'transparent', | ||
color: '#2196F3', | ||
margin: 4, | ||
}, | ||
buttonText: { | ||
color: '#2196F3', | ||
padding: 10, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import { StyleSheet, View, Text, Animated } from 'react-native'; | ||
|
||
interface ProgressBarProps { | ||
progress: number; | ||
} | ||
|
||
export function ProgressBar({ progress }: ProgressBarProps) { | ||
const progressAnim = useRef(new Animated.Value(0)).current; | ||
|
||
useEffect(() => { | ||
Animated.timing(progressAnim, { | ||
toValue: progress, | ||
duration: 500, | ||
useNativeDriver: false, | ||
}).start(); | ||
}, [progress, progressAnim]); | ||
|
||
const animatedWidth = progressAnim.interpolate({ | ||
inputRange: [0, 100], | ||
outputRange: ['0%', '100%'], | ||
}); | ||
|
||
return ( | ||
<View style={styles.progressBarContainer}> | ||
<Animated.View style={[styles.progressBar, { width: animatedWidth }]} /> | ||
<Text style={styles.progressBarText}>{progress}%</Text> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
progressBarContainer: { | ||
marginHorizontal: 10, | ||
}, | ||
progressBar: { | ||
height: 10, | ||
width: '100%', | ||
backgroundColor: 'rgba(5, 171, 55, 0.555)', | ||
alignSelf: 'center', | ||
borderRadius: 10, | ||
}, | ||
progressBarText: { | ||
color: '#333', | ||
textAlign: 'center', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { StyleSheet, Text } from 'react-native'; | ||
|
||
const MAX_STRING_LENGTH = 50; | ||
|
||
const formatString = (value: string) => { | ||
return value.length > MAX_STRING_LENGTH | ||
? value.slice(0, MAX_STRING_LENGTH) + | ||
'...' + | ||
value.slice(-MAX_STRING_LENGTH) | ||
: value; | ||
}; | ||
|
||
interface PropertyLabelProps { | ||
title: string; | ||
value: string | number; | ||
} | ||
|
||
export function PropertyLabel({ title, value }: PropertyLabelProps) { | ||
return ( | ||
<Text style={styles.label}> | ||
{title}: {formatString(value.toString())} | ||
</Text> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
label: { | ||
fontSize: 12, | ||
color: '#333', | ||
padding: 10, | ||
}, | ||
}); |