@boneframework/native-components 1.0.0 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Bone.ts +6 -0
- package/Components.ts +1 -0
- package/Contexts.ts +1 -0
- package/Hooks.ts +3 -0
- package/README.md +10 -1
- package/Screens.ts +4 -0
- package/Utilities.ts +1 -0
- package/api/client.js +29 -0
- package/api/expoPushTokens.js +7 -0
- package/api/notifications.js +9 -0
- package/api/ping.js +9 -0
- package/api/users.js +35 -0
- package/components/ActivityIndicator.js +48 -0
- package/components/Animation.js +21 -0
- package/components/ApiInterceptor.js +104 -0
- package/components/Button.js +40 -0
- package/components/Card.js +56 -0
- package/components/CategoryPickerItem.js +31 -0
- package/components/DateTimePicker.js +12 -0
- package/components/Icon.js +28 -0
- package/components/Image.js +61 -0
- package/components/ImageInput.tsx +97 -0
- package/components/ImageInputList.tsx +34 -0
- package/components/ListItemDeleteAction.tsx +30 -0
- package/components/ListItemFlipswitch.tsx +60 -0
- package/components/ListItemSeparator.tsx +23 -0
- package/components/ListItemSwipable.tsx +64 -0
- package/components/OfflineNotice.tsx +36 -0
- package/components/Picker.tsx +87 -0
- package/components/PickerItem.tsx +20 -0
- package/components/PickerItemComponent.tsx +14 -0
- package/components/RoundIconButton.tsx +36 -0
- package/components/Screen.tsx +26 -0
- package/components/SessionProvider.tsx +31 -0
- package/components/Text.tsx +15 -0
- package/components/TextInput.tsx +39 -0
- package/contexts/auth.js +5 -0
- package/hooks/useApi.js +20 -0
- package/hooks/useAuth.js +37 -0
- package/package.json +14 -3
- package/screens/RegisterScreen.tsx +87 -0
- package/screens/WelcomeScreen.tsx +50 -0
- package/utilities/authStorage.js +80 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {StyleSheet, TouchableWithoutFeedback, View} from "react-native";
|
|
3
|
+
import {MaterialCommunityIcons} from '@expo/vector-icons';
|
|
4
|
+
|
|
5
|
+
import colors from '../config/colors'
|
|
6
|
+
|
|
7
|
+
function ListItemDeleteAction({onPress}) {
|
|
8
|
+
return (
|
|
9
|
+
<TouchableWithoutFeedback onPress={onPress}>
|
|
10
|
+
<View style={styles.deleteBox} >
|
|
11
|
+
<MaterialCommunityIcons
|
|
12
|
+
name="trash-can"
|
|
13
|
+
size={35}
|
|
14
|
+
color={colors.white}
|
|
15
|
+
/>
|
|
16
|
+
</View>
|
|
17
|
+
</TouchableWithoutFeedback>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const styles = StyleSheet.create({
|
|
22
|
+
deleteBox: {
|
|
23
|
+
justifyContent: "center",
|
|
24
|
+
alignItems: "center",
|
|
25
|
+
backgroundColor: colors.danger,
|
|
26
|
+
width: 70
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
export default ListItemDeleteAction;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {StyleSheet, View} from "react-native";
|
|
3
|
+
import ToggleSwitch from "toggle-switch-react-native";
|
|
4
|
+
import Image from "./Image";
|
|
5
|
+
import {MaterialCommunityIcons} from "@expo/vector-icons";
|
|
6
|
+
|
|
7
|
+
import Text from '../components/Text'
|
|
8
|
+
import colors from "../config/colors";
|
|
9
|
+
import useStyle from "../hooks/useStyle";
|
|
10
|
+
|
|
11
|
+
function ListItemFlipswitch({title, subtitle, IconComponent, isOn, onColor, offColor, onToggle = () => {}}) {
|
|
12
|
+
const style = useStyle();
|
|
13
|
+
const styles = StyleSheet.create({
|
|
14
|
+
container: {
|
|
15
|
+
flexDirection: 'row',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
padding: 15,
|
|
18
|
+
backgroundColor: style.box.backgroundColor
|
|
19
|
+
},
|
|
20
|
+
detailsContainer: {
|
|
21
|
+
flex: 1,
|
|
22
|
+
marginLeft: 10,
|
|
23
|
+
justifyContent: "center"
|
|
24
|
+
},
|
|
25
|
+
image: {
|
|
26
|
+
width: 70,
|
|
27
|
+
height: 70,
|
|
28
|
+
borderRadius: 35,
|
|
29
|
+
},
|
|
30
|
+
title: {
|
|
31
|
+
color: style.text.color,
|
|
32
|
+
fontWeight: "500",
|
|
33
|
+
},
|
|
34
|
+
subtitle: {
|
|
35
|
+
color: colors.medium
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
onColor = onColor ? onColor : style.flipswitch.onColor
|
|
40
|
+
offColor = offColor ? offColor : style.flipswitch.offColor
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<View style={styles.container}>
|
|
44
|
+
{IconComponent}
|
|
45
|
+
<View style={styles.detailsContainer}>
|
|
46
|
+
<Text style={styles.title} numberOfLines={1}>{title}</Text>
|
|
47
|
+
{subtitle && <Text numberOfLines={2} style={styles.subtitle}>{subtitle}</Text> }
|
|
48
|
+
</View>
|
|
49
|
+
<ToggleSwitch
|
|
50
|
+
isOn={isOn}
|
|
51
|
+
onColor={onColor}
|
|
52
|
+
offColor={offColor}
|
|
53
|
+
size="large"
|
|
54
|
+
onToggle={onToggle}
|
|
55
|
+
/>
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default ListItemFlipswitch;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {StyleSheet, View} from "react-native";
|
|
3
|
+
|
|
4
|
+
import colors from '../config/colors'
|
|
5
|
+
import useStyle from "../hooks/useStyle";
|
|
6
|
+
|
|
7
|
+
function ListItemSeparator() {
|
|
8
|
+
const style = useStyle();
|
|
9
|
+
|
|
10
|
+
const styles = StyleSheet.create({
|
|
11
|
+
separator: {
|
|
12
|
+
width: '100%',
|
|
13
|
+
height: 1,
|
|
14
|
+
backgroundColor: style.backgroundColor
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<View style={styles.separator} />
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default ListItemSeparator;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {StyleSheet, TouchableHighlight, View} from "react-native";
|
|
3
|
+
import Swipeable from 'react-native-gesture-handler/Swipeable';
|
|
4
|
+
|
|
5
|
+
import Image from '../components/Image'
|
|
6
|
+
import Text from '../components/Text'
|
|
7
|
+
import colors from '../config/colors'
|
|
8
|
+
import {MaterialCommunityIcons} from "@expo/vector-icons";
|
|
9
|
+
import useStyle from "../hooks/useStyle";
|
|
10
|
+
|
|
11
|
+
function ListItemSwipable({title, subtitle, image, IconComponent, onPress, renderRightActions, displayCheverons}) {
|
|
12
|
+
const style = useStyle();
|
|
13
|
+
|
|
14
|
+
if (!title && subtitle) {
|
|
15
|
+
title = subtitle;
|
|
16
|
+
subtitle = null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const styles = StyleSheet.create({
|
|
20
|
+
container: {
|
|
21
|
+
flexDirection: 'row',
|
|
22
|
+
alignItems: 'center',
|
|
23
|
+
padding: 15,
|
|
24
|
+
backgroundColor: style.box.backgroundColor
|
|
25
|
+
},
|
|
26
|
+
detailsContainer: {
|
|
27
|
+
flex: 1,
|
|
28
|
+
marginLeft: 10,
|
|
29
|
+
justifyContent: "center"
|
|
30
|
+
},
|
|
31
|
+
image: {
|
|
32
|
+
width: 70,
|
|
33
|
+
height: 70,
|
|
34
|
+
borderRadius: 35,
|
|
35
|
+
},
|
|
36
|
+
title: {
|
|
37
|
+
color: style.text.color,
|
|
38
|
+
fontWeight: "500"
|
|
39
|
+
},
|
|
40
|
+
subtitle: {
|
|
41
|
+
color: colors.medium
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Swipeable renderRightActions={renderRightActions}>
|
|
47
|
+
<TouchableHighlight underlayColor={colors.light} onPress={onPress} >
|
|
48
|
+
<View style={styles.container}>
|
|
49
|
+
{ IconComponent }
|
|
50
|
+
{ image && <Image style={styles.image} source={image}></Image> }
|
|
51
|
+
<View style={styles.detailsContainer}>
|
|
52
|
+
<Text style={styles.title} numberOfLines={1}>
|
|
53
|
+
{ title }
|
|
54
|
+
</Text>
|
|
55
|
+
{subtitle && <Text numberOfLines={2} style={styles.subtitle}>{subtitle}</Text> }
|
|
56
|
+
</View>
|
|
57
|
+
{ displayCheverons && <MaterialCommunityIcons name={'chevron-right'} size={25} color={colors.medium}/> }
|
|
58
|
+
</View>
|
|
59
|
+
</TouchableHighlight>
|
|
60
|
+
</Swipeable>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default ListItemSwipable;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {StyleSheet, View} from "react-native";
|
|
3
|
+
import {useNetInfo} from "@react-native-community/netinfo";
|
|
4
|
+
|
|
5
|
+
import colors from "../config/colors";
|
|
6
|
+
import Text from "./Text";
|
|
7
|
+
|
|
8
|
+
function OfflineNotice(props) {
|
|
9
|
+
const netInfo = useNetInfo();
|
|
10
|
+
|
|
11
|
+
if (netInfo.type !== 'unkown' && netInfo.isInternetReachable === false) {
|
|
12
|
+
return(
|
|
13
|
+
<View style={styles.container}>
|
|
14
|
+
<Text style={styles.text}>No Internet connection</Text>
|
|
15
|
+
</View>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const styles = StyleSheet.create({
|
|
23
|
+
container: {
|
|
24
|
+
backgroundColor: colors.primary,
|
|
25
|
+
color: colors.white,
|
|
26
|
+
alignItems: "center",
|
|
27
|
+
justifyContent: "center",
|
|
28
|
+
padding: 10,
|
|
29
|
+
paddingTop: 20
|
|
30
|
+
},
|
|
31
|
+
text: {
|
|
32
|
+
color: colors.white,
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export default OfflineNotice;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React, {useState} from 'react';
|
|
2
|
+
import {FlatList, Modal, StyleSheet, TextInput, TouchableWithoutFeedback, View} from "react-native";
|
|
3
|
+
import {MaterialCommunityIcons} from "@expo/vector-icons";
|
|
4
|
+
|
|
5
|
+
import Button from './Button'
|
|
6
|
+
import Text from './Text'
|
|
7
|
+
import PickerItem from './PickerItem'
|
|
8
|
+
import PickerItemComponent from './PickerItemComponent'
|
|
9
|
+
import Screen from './Screen'
|
|
10
|
+
import useStyle from "../hooks/useStyle";
|
|
11
|
+
|
|
12
|
+
function Picker({
|
|
13
|
+
icon,
|
|
14
|
+
items,
|
|
15
|
+
onSelectItem,
|
|
16
|
+
PickerItemComponent = PickerItem,
|
|
17
|
+
placeholder,
|
|
18
|
+
selectedItem,
|
|
19
|
+
width = '100%',
|
|
20
|
+
numColumns = 1
|
|
21
|
+
}) {
|
|
22
|
+
const [modalVisible, setModalVisible] = useState(false);
|
|
23
|
+
const defaultStyles = useStyle();
|
|
24
|
+
|
|
25
|
+
const style = StyleSheet.create({
|
|
26
|
+
container: {
|
|
27
|
+
backgroundColor: defaultStyles.formInput.backgroundColor,
|
|
28
|
+
borderRadius: 25,
|
|
29
|
+
flexDirection: 'row',
|
|
30
|
+
width: '100%',
|
|
31
|
+
padding: 15,
|
|
32
|
+
marginVertical: 10,
|
|
33
|
+
},
|
|
34
|
+
icon: {
|
|
35
|
+
marginRight: 10
|
|
36
|
+
},
|
|
37
|
+
modal: {
|
|
38
|
+
flex: 1,
|
|
39
|
+
padding: 15,
|
|
40
|
+
backgroundColor: defaultStyles.backgroundColor,
|
|
41
|
+
color: defaultStyles.text.color
|
|
42
|
+
},
|
|
43
|
+
placeholder: {
|
|
44
|
+
flex: 1,
|
|
45
|
+
color: defaultStyles.colors.medium
|
|
46
|
+
},
|
|
47
|
+
text: {
|
|
48
|
+
flex: 1
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<View>
|
|
54
|
+
<TouchableWithoutFeedback onPress={() => setModalVisible(true)}>
|
|
55
|
+
<View style={[style.container, {width: width}]}>
|
|
56
|
+
{icon && <MaterialCommunityIcons name={icon} size={25} color={defaultStyles.colors.medium} style={style.icon} />}
|
|
57
|
+
<Text style={selectedItem ? [defaultStyles.text, style.text] : [defaultStyles.text, style.placeholder] } >
|
|
58
|
+
{ selectedItem ? selectedItem.label : placeholder }
|
|
59
|
+
</Text>
|
|
60
|
+
<MaterialCommunityIcons name="chevron-down" size={25} color={defaultStyles.colors.medium} />
|
|
61
|
+
</View>
|
|
62
|
+
</TouchableWithoutFeedback>
|
|
63
|
+
|
|
64
|
+
<Modal visible={modalVisible} animationType="slide">
|
|
65
|
+
<Screen style={style.modal}>
|
|
66
|
+
<Button title="Close" onPress={() => setModalVisible(false)}/>
|
|
67
|
+
<FlatList
|
|
68
|
+
data={items}
|
|
69
|
+
keyExtractor={item => item.value}
|
|
70
|
+
numColumns={numColumns}
|
|
71
|
+
renderItem={({item}) =>
|
|
72
|
+
<PickerItemComponent
|
|
73
|
+
item={item}
|
|
74
|
+
label={item.label}
|
|
75
|
+
onPress={() => {
|
|
76
|
+
setModalVisible(false);
|
|
77
|
+
onSelectItem(item);
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
} />
|
|
81
|
+
</Screen>
|
|
82
|
+
</Modal>
|
|
83
|
+
</View>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export default Picker;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {StyleSheet, TouchableOpacity, View} from "react-native";
|
|
3
|
+
|
|
4
|
+
import Text from './Text';
|
|
5
|
+
|
|
6
|
+
function PickerItem({ item, onPress }) {
|
|
7
|
+
return (
|
|
8
|
+
<TouchableOpacity onPress={onPress}>
|
|
9
|
+
<Text style={styles.text}>{item.label}</Text>
|
|
10
|
+
</TouchableOpacity>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const styles = StyleSheet.create({
|
|
15
|
+
text: {
|
|
16
|
+
padding: 20
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export default PickerItem;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {StyleSheet, View} from "react-native";
|
|
3
|
+
|
|
4
|
+
function PickerItemComponent({item, onPress}) {
|
|
5
|
+
return <View style={styles.container}></View>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const styles = StyleSheet.create({
|
|
9
|
+
container: {
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export default PickerItemComponent;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {StyleSheet, TouchableOpacity, View} from "react-native";
|
|
3
|
+
import {MaterialCommunityIcons} from "@expo/vector-icons";
|
|
4
|
+
|
|
5
|
+
import colors from '../config/colors'
|
|
6
|
+
|
|
7
|
+
function RoundIconButton({ icon, onPress = () => {}, style }) {
|
|
8
|
+
const combinedStyle = { ...styles.container, ...style };
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<TouchableOpacity onPress={ onPress } >
|
|
12
|
+
<View style={combinedStyle}>
|
|
13
|
+
<MaterialCommunityIcons style={styles.icon} name={icon} size={40}/>
|
|
14
|
+
</View>
|
|
15
|
+
</TouchableOpacity>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const styles = StyleSheet.create({
|
|
20
|
+
container: {
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
justifyContent: 'center',
|
|
23
|
+
backgroundColor: colors.primary,
|
|
24
|
+
borderColor: colors.white,
|
|
25
|
+
borderWidth: 5,
|
|
26
|
+
borderRadius: 40,
|
|
27
|
+
height: 80,
|
|
28
|
+
width: 80,
|
|
29
|
+
bottom: 25
|
|
30
|
+
},
|
|
31
|
+
icon: {
|
|
32
|
+
color: colors.white
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export default RoundIconButton;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {SafeAreaView, StyleSheet, View} from "react-native";
|
|
3
|
+
import Constants from "expo-constants";
|
|
4
|
+
|
|
5
|
+
function Screen({children, style}) {
|
|
6
|
+
return (
|
|
7
|
+
<SafeAreaView style={[style, styles.screen]}>
|
|
8
|
+
<View style={[style, styles.view]}>
|
|
9
|
+
{children}
|
|
10
|
+
</View>
|
|
11
|
+
</SafeAreaView>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const styles = StyleSheet.create({
|
|
16
|
+
screen: {
|
|
17
|
+
paddingTop: Constants.statusBarHeight,
|
|
18
|
+
flex: 1,
|
|
19
|
+
height: '100%'
|
|
20
|
+
},
|
|
21
|
+
view: {
|
|
22
|
+
flex: 1
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export default Screen;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, {useState} from 'react';
|
|
2
|
+
|
|
3
|
+
import AuthContext from "../contexts/auth";
|
|
4
|
+
import useAuth from "../hooks/useAuth";
|
|
5
|
+
|
|
6
|
+
function SessionProvider(props: object) {
|
|
7
|
+
const [user, setUser] = useState(null);
|
|
8
|
+
const auth = useAuth();
|
|
9
|
+
setUser(auth.user);
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<AuthContext.Provider
|
|
13
|
+
value={{
|
|
14
|
+
signIn: async (authToken: string) => {
|
|
15
|
+
auth.login(authToken);
|
|
16
|
+
setUser(auth.user);
|
|
17
|
+
},
|
|
18
|
+
signOut: () => {
|
|
19
|
+
auth.logout();
|
|
20
|
+
setUser(null);
|
|
21
|
+
},
|
|
22
|
+
user,
|
|
23
|
+
}}>
|
|
24
|
+
{props.children}
|
|
25
|
+
</AuthContext.Provider>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export default SessionProvider;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {Text as NativeText, StyleSheet} from "react-native";
|
|
3
|
+
|
|
4
|
+
import defaultStyles from '../config/styles'
|
|
5
|
+
import colors from "../config/colors";
|
|
6
|
+
|
|
7
|
+
function Text({children, style, ...otherProps}) {
|
|
8
|
+
return (
|
|
9
|
+
<NativeText style={[defaultStyles.text, style]} {...otherProps} >
|
|
10
|
+
{children}
|
|
11
|
+
</NativeText>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default Text;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {StyleSheet, TextInput as NativeTextInput, View} from "react-native";
|
|
3
|
+
import {MaterialCommunityIcons} from "@expo/vector-icons";
|
|
4
|
+
|
|
5
|
+
import useStyle from "../hooks/useStyle";
|
|
6
|
+
|
|
7
|
+
function TextInput({ icon, width = '100%', ...otherProps }) {
|
|
8
|
+
const defaultStyles = useStyle();
|
|
9
|
+
|
|
10
|
+
const styles = StyleSheet.create({
|
|
11
|
+
container: {
|
|
12
|
+
backgroundColor: defaultStyles.formInput.backgroundColor,
|
|
13
|
+
borderRadius: 25,
|
|
14
|
+
flexDirection: 'row',
|
|
15
|
+
padding: 15,
|
|
16
|
+
marginVertical: 10,
|
|
17
|
+
},
|
|
18
|
+
input: {
|
|
19
|
+
flex: 1,
|
|
20
|
+
color: defaultStyles.formInput.color,
|
|
21
|
+
},
|
|
22
|
+
icon: {
|
|
23
|
+
marginRight: 10
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<View style={ [styles.container, {width}] }>
|
|
29
|
+
{icon && <MaterialCommunityIcons name={icon} size={25} color={defaultStyles.colors.medium} style={styles.icon} />}
|
|
30
|
+
<NativeTextInput
|
|
31
|
+
placeholderTextColor={defaultStyles.colors.medium}
|
|
32
|
+
style={[styles.input, defaultStyles.text]}
|
|
33
|
+
{...otherProps}
|
|
34
|
+
/>
|
|
35
|
+
</View>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default TextInput;
|
package/contexts/auth.js
ADDED
package/hooks/useApi.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {useState} from "react";
|
|
2
|
+
|
|
3
|
+
export default useApi = (apiFunc) => {
|
|
4
|
+
const [error, setError] = useState(false);
|
|
5
|
+
const [headers, setHeaders] = useState([]);
|
|
6
|
+
const [data, setData] = useState([]);
|
|
7
|
+
const [loading, setLoading] = useState(false);
|
|
8
|
+
|
|
9
|
+
const request = async (...args) => {
|
|
10
|
+
setLoading(true);
|
|
11
|
+
const response = await apiFunc(...args);
|
|
12
|
+
setLoading(false);
|
|
13
|
+
setError(!response.ok);
|
|
14
|
+
setHeaders(response.headers);
|
|
15
|
+
setData(response.data);
|
|
16
|
+
return response;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {data, error, headers, loading, request}
|
|
20
|
+
}
|
package/hooks/useAuth.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {useContext} from "react";
|
|
2
|
+
|
|
3
|
+
import AuthContext from "../contexts/auth";
|
|
4
|
+
import authStorage from "../utilities/authStorage";
|
|
5
|
+
import useApi from "./useApi";
|
|
6
|
+
import usersApi from "../api/users";
|
|
7
|
+
|
|
8
|
+
export default useAuth = () => {
|
|
9
|
+
const profileApi = useApi(usersApi.getProfile);
|
|
10
|
+
const {user, setUser} = useContext(AuthContext);
|
|
11
|
+
|
|
12
|
+
const login = async authToken => {
|
|
13
|
+
// possibly don't wait here?
|
|
14
|
+
await authStorage.storeAuthToken(authToken).then(async () => {
|
|
15
|
+
const user = await profileApi.request(authToken);
|
|
16
|
+
authStorage.storeUser(user.data);
|
|
17
|
+
user.data.authToken = authToken;
|
|
18
|
+
setUser(user.data);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const updateUser = async user => {
|
|
23
|
+
const authToken = user.authToken;
|
|
24
|
+
await delete user.authToken;
|
|
25
|
+
authStorage.storeUser(user);
|
|
26
|
+
user.authToken = authToken;
|
|
27
|
+
setUser({...user});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const logout = () => {
|
|
31
|
+
setUser(null);
|
|
32
|
+
authStorage.removeAuthToken();
|
|
33
|
+
authStorage.removeUser();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {login, logout, updateUser, user};
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boneframework/native-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Expo Components for Bone Framework",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/Bone.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
@@ -25,5 +25,16 @@
|
|
|
25
25
|
"url": "https://github.com/boneframework/native-components/issues"
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/boneframework/native-components#readme",
|
|
28
|
-
"publishConfig": {
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@react-native-async-storage/async-storage": "^1.24.0",
|
|
33
|
+
"apisauce": "^3.0.1",
|
|
34
|
+
"expo-auth-session": "^5.5.2",
|
|
35
|
+
"expo-secure-store": "^13.0.2",
|
|
36
|
+
"jwt-decode": "^4.0.0",
|
|
37
|
+
"react": "18.2.0",
|
|
38
|
+
"yup": "^1.4.0"
|
|
39
|
+
}
|
|
29
40
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { router } from 'expo-router';
|
|
2
|
+
import React, {useState} from 'react';
|
|
3
|
+
import {Image, ImageBackground, Keyboard, StyleSheet, TouchableOpacity, View} from "react-native";
|
|
4
|
+
import * as Yup from 'yup'
|
|
5
|
+
|
|
6
|
+
import ActivityIndicator from "@/components/ActivityIndicator";
|
|
7
|
+
import useApi from "@/hooks/useApi";
|
|
8
|
+
import usersApi from '@/api/users';
|
|
9
|
+
import {ErrorMessage, FormField, Form, SubmitButton} from '../components/forms'
|
|
10
|
+
import Icon from "@/components/Icon";
|
|
11
|
+
|
|
12
|
+
const validationSchema = Yup.object().shape({
|
|
13
|
+
email: Yup.string().required().email().label('Email'),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
function RegisterScreen({postRegisterUrl}) {
|
|
17
|
+
const registerApi = useApi(usersApi.register);
|
|
18
|
+
const [error, setError] = useState();
|
|
19
|
+
const onClose = () => router.back();
|
|
20
|
+
|
|
21
|
+
const handleSubmit = async userInfo => {
|
|
22
|
+
Keyboard.dismiss();
|
|
23
|
+
const result = await registerApi.request(userInfo);
|
|
24
|
+
|
|
25
|
+
if (!result.ok) {
|
|
26
|
+
if (result.data) {
|
|
27
|
+
setError(result.data.error);
|
|
28
|
+
} else {
|
|
29
|
+
setError('An unexpected error occured');
|
|
30
|
+
console.error(result);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
router.navigate(postRegisterUrl);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<>
|
|
41
|
+
<ActivityIndicator visible={registerApi.loading} type={'overlay'}/>
|
|
42
|
+
<ImageBackground blurRadius={10} style={styles.background} source={require('../assets/background.png')} >
|
|
43
|
+
<View style={styles.container}>
|
|
44
|
+
<TouchableOpacity style={styles.cancelButton} onPress={onClose}>
|
|
45
|
+
<Icon size={75} name={'close'} />
|
|
46
|
+
</TouchableOpacity>
|
|
47
|
+
<Image style={styles.logo} source={require('../assets/logo.png')} />
|
|
48
|
+
|
|
49
|
+
<Form
|
|
50
|
+
initialValues={{ email: ''}}
|
|
51
|
+
onSubmit={handleSubmit}
|
|
52
|
+
validationSchema={validationSchema}
|
|
53
|
+
>
|
|
54
|
+
<ErrorMessage error={error} visible={error} />
|
|
55
|
+
<FormField
|
|
56
|
+
name="email"
|
|
57
|
+
icon="email"
|
|
58
|
+
placeholder="Email"
|
|
59
|
+
autoCapitalize="none"
|
|
60
|
+
keyboardType="email-address"
|
|
61
|
+
textContentType="emailAddress"
|
|
62
|
+
/>
|
|
63
|
+
<SubmitButton color="primary" title="Register" />
|
|
64
|
+
</Form>
|
|
65
|
+
</View>
|
|
66
|
+
</ImageBackground>
|
|
67
|
+
</>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const styles = StyleSheet.create({
|
|
72
|
+
container: {
|
|
73
|
+
paddingHorizontal: 20,
|
|
74
|
+
},
|
|
75
|
+
logo: {
|
|
76
|
+
width: 150,
|
|
77
|
+
height: 105,
|
|
78
|
+
alignSelf: "center",
|
|
79
|
+
marginTop: 50,
|
|
80
|
+
marginBottom: 20,
|
|
81
|
+
},
|
|
82
|
+
background: {
|
|
83
|
+
height: '100%'
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
export default RegisterScreen;
|