Skip to content

Commit e403f61

Browse files
committed
added CosyncStorage React Expo
1 parent e7c23fe commit e403f61

30 files changed

+39471
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { StatusBar } from 'expo-status-bar';
2+
import { StyleSheet, Text, View } from 'react-native';
3+
import { AuthProvider } from './context/AuthContext';
4+
import AppNav from './components/AppNav';
5+
export default function App() {
6+
return (
7+
<>
8+
<StatusBar style='light' />
9+
10+
<AuthProvider>
11+
<AppNav/>
12+
</AuthProvider>
13+
</>
14+
);
15+
}
16+
17+
const styles = StyleSheet.create({
18+
container: {
19+
flex: 1,
20+
backgroundColor: '#fff',
21+
alignItems: 'center',
22+
justifyContent: 'center',
23+
},
24+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"expo": {
3+
"name": "CosyncStorageReactExpo",
4+
"slug": "CosyncStorageReactExpo",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"userInterfaceStyle": "light",
9+
"splash": {
10+
"image": "./assets/cosynclogo.png",
11+
"resizeMode": "contain",
12+
"backgroundColor": "#ffffff"
13+
},
14+
"updates": {
15+
"fallbackToCacheTimeout": 0
16+
},
17+
"assetBundlePatterns": [
18+
"**/*"
19+
],
20+
"ios": {
21+
"supportsTablet": true,
22+
"bundleIdentifier": "com.tolacambo.CosyncStorageReactExpo"
23+
},
24+
"android": {
25+
"adaptiveIcon": {
26+
"foregroundImage": "./assets/adaptive-icon.png",
27+
"backgroundColor": "#FFFFFF"
28+
},
29+
"package": "com.tolacambo.CosyncStorageReactExpo"
30+
},
31+
"web": {
32+
"favicon": "./assets/favicon.png"
33+
}
34+
}
35+
}
17.1 KB
Loading
6.25 KB
Loading
1.43 KB
Loading
21.9 KB
Loading
46.2 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo'],
5+
};
6+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
import React, { useContext } from 'react';
3+
import { NavigationContainer } from '@react-navigation/native';
4+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
5+
import RegisterScreen from '../screens/RegisterScreen';
6+
import LoginScreen from '../screens/LoginScreen';
7+
import HomeScreen from '../screens/HomeScreen';
8+
import { AuthContext } from '../context/AuthContext';
9+
10+
const Stack = createNativeStackNavigator();
11+
12+
13+
export default function AppNav() {
14+
15+
const { realmUser } = useContext(AuthContext);
16+
17+
return (
18+
<NavigationContainer>
19+
{realmUser ?
20+
<AppStack/> :
21+
<AuthStack/>
22+
}
23+
</NavigationContainer>
24+
25+
)
26+
}
27+
28+
29+
const AuthStack = () => {
30+
return (
31+
<Stack.Navigator>
32+
<Stack.Screen name="LoginScreen" component={LoginScreen} />
33+
<Stack.Screen name="RegisterScreen" component={RegisterScreen} />
34+
</Stack.Navigator>
35+
);
36+
};
37+
38+
39+
const AppStack = () => {
40+
return (
41+
<Stack.Navigator>
42+
<Stack.Screen name="Home" component={HomeScreen} options={{headerShown:false}}/>
43+
</Stack.Navigator>
44+
);
45+
};
46+
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
import React, { useEffect } from 'react';
2+
import { View, StyleSheet, Animated, Easing } from 'react-native';
3+
import PropTypes from 'prop-types';
4+
5+
const CircularProgressBar = (props) => {
6+
const {
7+
activeColor,
8+
passiveColor,
9+
baseColor,
10+
radius,
11+
percent,
12+
width,
13+
duration,
14+
children,
15+
} = props;
16+
17+
const initialValueHalfCircle = percent >= 50 ? 0 : 180;
18+
const initialValueInnerCircle = 0;
19+
const firstCircleAnimatedValue = new Animated.Value(initialValueHalfCircle);
20+
const secondCircleAnimatedValue = new Animated.Value(initialValueHalfCircle);
21+
const thirdCircleAnimatedValue = new Animated.Value(initialValueInnerCircle);
22+
const timePerDegree = duration / 360;
23+
const firstCircleColor = activeColor;
24+
const secondCircleColor = percent >= 50 ? activeColor : passiveColor;
25+
26+
const secondAnimation = () => {
27+
firstCircleAnimatedValue.setValue(initialValueHalfCircle);
28+
secondCircleAnimatedValue.setValue(initialValueHalfCircle);
29+
thirdCircleAnimatedValue.setValue(initialValueHalfCircle);
30+
Animated.parallel([
31+
Animated.timing(firstCircleAnimatedValue, {
32+
toValue: 180,
33+
duration: 180 * timePerDegree,
34+
useNativeDriver: true,
35+
easing: Easing.linear,
36+
}),
37+
Animated.timing(secondCircleAnimatedValue, {
38+
toValue: 180 + (percent - 50) * 3.6,
39+
duration: (180 + (percent - 50) * 3.6) * timePerDegree,
40+
useNativeDriver: true,
41+
easing: Easing.linear,
42+
}),
43+
Animated.timing(thirdCircleAnimatedValue, {
44+
toValue: (percent - 50) * 3.6,
45+
delay: 180 * timePerDegree,
46+
duration: timePerDegree * ((percent - 50) * 3.6),
47+
useNativeDriver: false,
48+
easing: Easing.linear,
49+
}),
50+
]).start();
51+
};
52+
53+
const firstAnimation = () => {
54+
Animated.timing(secondCircleAnimatedValue, {
55+
toValue: 180 + percent * 3.6,
56+
duration: percent * 3.6 * timePerDegree,
57+
useNativeDriver: true,
58+
easing: Easing.linear,
59+
}).start();
60+
};
61+
62+
useEffect(() => {
63+
if (percent < 50) {
64+
firstAnimation();
65+
} else {
66+
secondAnimation();
67+
}
68+
});
69+
70+
const renderHalf = (color, transforms = [], otherStyles = {}) => (
71+
<Animated.View
72+
style={[
73+
styles.half,
74+
{ backgroundColor: color, borderColor: color },
75+
{ width: radius, height: radius * 2, borderRadius: radius },
76+
{
77+
transform: [
78+
{ translateX: radius / 2 },
79+
...transforms,
80+
{ translateX: -radius / 2 },
81+
],
82+
},
83+
otherStyles,
84+
]}
85+
/>
86+
);
87+
88+
const rotate1 = firstCircleAnimatedValue.interpolate({
89+
inputRange: [0, 1],
90+
outputRange: ['0deg', '1deg'],
91+
});
92+
93+
const rotate2 = secondCircleAnimatedValue.interpolate({
94+
inputRange: [0, 1],
95+
outputRange: ['0deg', '1deg'],
96+
});
97+
98+
const rotate3 = thirdCircleAnimatedValue.interpolate({
99+
inputRange: [0, 1],
100+
outputRange: ['0deg', '1deg'],
101+
});
102+
103+
const elevation3 = thirdCircleAnimatedValue.interpolate({
104+
inputRange: [0, 1],
105+
outputRange: [0, -1],
106+
});
107+
108+
const innerCircleStyle = {
109+
backgroundColor: baseColor,
110+
width: 2 * radius - width,
111+
height: 2 * radius - width,
112+
borderRadius: radius,
113+
elevation: 1000,
114+
display: 'flex',
115+
justifyContent: 'center',
116+
alignItems: 'center',
117+
};
118+
119+
return (
120+
<View style={styles.container} key={percent}>
121+
<View
122+
style={[
123+
styles.outerCircle,
124+
{
125+
height: radius * 2,
126+
width: radius * 2,
127+
borderRadius: radius,
128+
backgroundColor: passiveColor,
129+
overflow: 'hidden',
130+
},
131+
]}
132+
>
133+
{renderHalf(firstCircleColor, [{ rotate: rotate1 }])}
134+
{renderHalf(secondCircleColor, [{ rotate: rotate2 }])}
135+
{renderHalf(passiveColor, [{ rotate: rotate3 }], {
136+
elevation: elevation3, zIndex: elevation3,
137+
})}
138+
{<View style={innerCircleStyle}>
139+
{children}
140+
</View>}
141+
</View>
142+
</View>
143+
);
144+
};
145+
146+
CircularProgressBar.propTypes = {
147+
activeColor: PropTypes.string.isRequired,
148+
passiveColor: PropTypes.string.isRequired,
149+
baseColor: PropTypes.string.isRequired,
150+
width: PropTypes.number.isRequired,
151+
radius: PropTypes.number.isRequired,
152+
percent: PropTypes.number.isRequired,
153+
duration: PropTypes.number.isRequired,
154+
children: PropTypes.element,
155+
};
156+
157+
const styles = StyleSheet.create({
158+
container: {
159+
flex: 1,
160+
backgroundColor: '#fff',
161+
alignItems: 'center',
162+
justifyContent: 'center',
163+
},
164+
outerCircle: {
165+
position: 'relative',
166+
justifyContent: 'center',
167+
alignItems: 'center',
168+
},
169+
half: {
170+
position: 'absolute',
171+
left: 0,
172+
top: 0,
173+
borderTopRightRadius: 0,
174+
borderBottomRightRadius: 0,
175+
},
176+
});
177+
178+
export default CircularProgressBar;

0 commit comments

Comments
 (0)