@boneframework/native-components 1.0.4 → 1.0.6
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/components/forms/ErrorMessage.js +20 -0
- package/components/forms/Form.js +21 -0
- package/components/forms/FormDateTimePicker.js +31 -0
- package/components/forms/FormField.js +26 -0
- package/components/forms/FormImagePicker.js +30 -0
- package/components/forms/FormPicker.js +30 -0
- package/components/forms/SubmitButton.js +14 -0
- package/components/forms/index.js +7 -0
- package/package.json +1 -1
- package/screens/RegisterScreen.tsx +4 -4
- package/screens/WelcomeScreen.tsx +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {StyleSheet} from "react-native";
|
|
3
|
+
|
|
4
|
+
import Text from '../Text'
|
|
5
|
+
|
|
6
|
+
function ErrorMessage({error, visible}) {
|
|
7
|
+
if (!visible || !error) return null;
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<Text style={styles.error}>{error}</Text>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const styles = StyleSheet.create({
|
|
15
|
+
error: {
|
|
16
|
+
color: 'tomato'
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export default ErrorMessage;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {Formik} from "formik";
|
|
3
|
+
import {View} from "react-native";
|
|
4
|
+
|
|
5
|
+
function Form({initialValues, onSubmit, validationSchema, children}) {
|
|
6
|
+
return (
|
|
7
|
+
<Formik
|
|
8
|
+
initialValues={initialValues}
|
|
9
|
+
onSubmit={onSubmit}
|
|
10
|
+
validationSchema={validationSchema}
|
|
11
|
+
>
|
|
12
|
+
{() => (
|
|
13
|
+
<View>
|
|
14
|
+
{children}
|
|
15
|
+
</View>
|
|
16
|
+
)}
|
|
17
|
+
</Formik>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default Form;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import RNDateTimePicker from '@react-native-community/datetimepicker';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import {Field, useFormikContext} from "formik";
|
|
4
|
+
import DateTimePicker from "../DateTimePicker";
|
|
5
|
+
import {StyleSheet} from "react-native";
|
|
6
|
+
import useStyle from "../../hooks/useStyle";
|
|
7
|
+
|
|
8
|
+
function FormDateTimePicker ({...props}) {
|
|
9
|
+
|
|
10
|
+
const { values, setFieldValue } = useFormikContext();
|
|
11
|
+
const style = useStyle();
|
|
12
|
+
|
|
13
|
+
const styles = StyleSheet.create({
|
|
14
|
+
picker: {
|
|
15
|
+
flex: 1,
|
|
16
|
+
width: '50%',
|
|
17
|
+
backgroundColor: style.backgroundColor,
|
|
18
|
+
borderRadius: 25,
|
|
19
|
+
flexDirection: 'row',
|
|
20
|
+
padding: 15,
|
|
21
|
+
marginVertical: 10,
|
|
22
|
+
marginHorizontal: 10,
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return <Field style={styles.picker} component={DateTimePicker} value={values[props.name]} {...props} onChange={(event, value) => {
|
|
27
|
+
setFieldValue(props.name, new Date(value));
|
|
28
|
+
}} />
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default FormDateTimePicker;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {useFormikContext} from "formik";
|
|
3
|
+
import {StyleSheet, View} from "react-native";
|
|
4
|
+
|
|
5
|
+
import TextInput from "../TextInput";
|
|
6
|
+
import ErrorMessage from "./ErrorMessage";
|
|
7
|
+
import useStyle from "../../hooks/useStyle";
|
|
8
|
+
|
|
9
|
+
function FormField({name, width, ...otherProps}) {
|
|
10
|
+
const {setFieldTouched, handleChange, errors, values, touched} = useFormikContext();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<View>
|
|
14
|
+
<TextInput
|
|
15
|
+
onChangeText={handleChange(name)}
|
|
16
|
+
onBlur={() => setFieldTouched(name)}
|
|
17
|
+
value={values[name]}
|
|
18
|
+
width={width}
|
|
19
|
+
{...otherProps}
|
|
20
|
+
/>
|
|
21
|
+
<ErrorMessage error={errors[name]} visible={touched[name]}/>
|
|
22
|
+
</View>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default FormField;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {View} from "react-native";
|
|
3
|
+
import {useFormikContext} from "formik";
|
|
4
|
+
|
|
5
|
+
import ErrorMessage from './ErrorMessage'
|
|
6
|
+
import ImageInputList from '../ImageInputList'
|
|
7
|
+
|
|
8
|
+
function FormImagePicker({ name }) {
|
|
9
|
+
const {setFieldValue, touched, values, errors} = useFormikContext();
|
|
10
|
+
const imageUris = values[name]
|
|
11
|
+
const handleAdd = (uri) => {
|
|
12
|
+
setFieldValue(name, [...imageUris, uri])
|
|
13
|
+
};
|
|
14
|
+
const handleRemove = (uri) => {
|
|
15
|
+
setFieldValue(name, imageUris.filter(imageUri => imageUri !== uri))
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<View>
|
|
20
|
+
<ImageInputList
|
|
21
|
+
imageUris={imageUris}
|
|
22
|
+
onAddImage={handleAdd}
|
|
23
|
+
onRemoveImage={handleRemove}
|
|
24
|
+
/>
|
|
25
|
+
<ErrorMessage error={errors[name]} visible={touched[name]} />
|
|
26
|
+
</View>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default FormImagePicker;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {View} from "react-native";
|
|
3
|
+
|
|
4
|
+
import Picker from '../Picker'
|
|
5
|
+
import PickerItemComponent from '../PickerItemComponent'
|
|
6
|
+
import ErrorMessage from "./ErrorMessage";
|
|
7
|
+
import {useFormikContext} from "formik";
|
|
8
|
+
|
|
9
|
+
function FormPicker({items, name, PickerItemComponent, placeholder, width, numColumns, ...otherProps}) {
|
|
10
|
+
const {setFieldValue, touched, values, errors} = useFormikContext();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<View>
|
|
14
|
+
<Picker
|
|
15
|
+
items={items}
|
|
16
|
+
numColumns={numColumns}
|
|
17
|
+
onSelectItem={(value) => {
|
|
18
|
+
setFieldValue(name, value);
|
|
19
|
+
}}
|
|
20
|
+
PickerItemComponent={PickerItemComponent}
|
|
21
|
+
placeholder={placeholder}
|
|
22
|
+
selectedItem={values[name]} {...otherProps}
|
|
23
|
+
width={width}
|
|
24
|
+
/>
|
|
25
|
+
<ErrorMessage error={errors[name]} visible={touched[name]} />
|
|
26
|
+
</View>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default FormPicker;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import Button from "../Button";
|
|
4
|
+
import {useFormikContext} from "formik";
|
|
5
|
+
|
|
6
|
+
function SubmitButton({title, ...otherProps}) {
|
|
7
|
+
const {handleSubmit} = useFormikContext();
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<Button color="primary" title={title} onPress={handleSubmit} {...otherProps} />
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default SubmitButton;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as Form} from './Form';
|
|
2
|
+
export { default as FormDateTimePicker} from './FormDateTimePicker';
|
|
3
|
+
export { default as FormField} from './FormField';
|
|
4
|
+
export { default as FormImagePicker} from './FormImagePicker';
|
|
5
|
+
export { default as FormPicker} from './FormPicker';
|
|
6
|
+
export { default as ErrorMessage} from './ErrorMessage';
|
|
7
|
+
export { default as SubmitButton} from './SubmitButton';
|
package/package.json
CHANGED
|
@@ -3,11 +3,11 @@ import React, {useState} from 'react';
|
|
|
3
3
|
import {Image, ImageBackground, Keyboard, StyleSheet, TouchableOpacity, View} from "react-native";
|
|
4
4
|
import * as Yup from 'yup'
|
|
5
5
|
|
|
6
|
-
import ActivityIndicator from "
|
|
7
|
-
import useApi from "
|
|
8
|
-
import usersApi from '
|
|
6
|
+
import ActivityIndicator from "../components/ActivityIndicator";
|
|
7
|
+
import useApi from "../hooks/useApi";
|
|
8
|
+
import usersApi from '../api/users';
|
|
9
9
|
import {ErrorMessage, FormField, Form, SubmitButton} from '../components/forms'
|
|
10
|
-
import Icon from "
|
|
10
|
+
import Icon from "../components/Icon";
|
|
11
11
|
|
|
12
12
|
const validationSchema = Yup.object().shape({
|
|
13
13
|
email: Yup.string().required().email().label('Email'),
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import {Image, ImageBackground, StyleSheet, Text, View} from "react-native";
|
|
3
3
|
import {exchangeCodeAsync, makeRedirectUri, useAuthRequest} from "expo-auth-session";
|
|
4
4
|
|
|
5
|
-
import Button from '
|
|
5
|
+
import Button from '../components/Button'
|
|
6
6
|
import colors from '@/config/colors'
|
|
7
7
|
|
|
8
8
|
function WelcomeScreen({loginOnPress = () => {}, registerOnPress = () => {}}) {
|