@hitesh0009/react-native-basic-form 1.3.1 → 1.3.2
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/README.md +0 -2
- package/basic_usage/example.js +48 -17
- package/package.json +1 -1
package/README.md
CHANGED
package/basic_usage/example.js
CHANGED
|
@@ -3,27 +3,58 @@ import { View } from "react-native";
|
|
|
3
3
|
import { Form } from "react-native-basic-form";
|
|
4
4
|
|
|
5
5
|
export default function App() {
|
|
6
|
+
// 👉 Form state is owned by YOU, not by the Form component
|
|
7
|
+
// The library is stateless by design
|
|
6
8
|
const [name, setName] = useState("");
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
// 👉 Schema controls the entire form UI
|
|
11
|
+
// Changing this JSON changes the form
|
|
12
|
+
const formSchema = [
|
|
13
|
+
{
|
|
14
|
+
// Layout block: controls how children are arranged
|
|
15
|
+
layout: "column",
|
|
16
|
+
spacing: 16, // space between fields
|
|
17
|
+
|
|
18
|
+
// Children = actual form fields
|
|
19
|
+
children: [
|
|
20
|
+
{
|
|
21
|
+
// Input field
|
|
22
|
+
type: "input",
|
|
23
|
+
label: "Name",
|
|
24
|
+
|
|
25
|
+
// All TextInput behavior goes inside inputProps
|
|
26
|
+
inputProps: {
|
|
27
|
+
placeholder: "Enter your name",
|
|
28
|
+
value: name, // controlled value
|
|
29
|
+
onChangeText: setName // update state
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
{
|
|
34
|
+
// Button field
|
|
35
|
+
type: "button",
|
|
36
|
+
label: "Submit",
|
|
37
|
+
|
|
38
|
+
// Button behavior goes inside buttonProps
|
|
39
|
+
buttonProps: {
|
|
40
|
+
buttonText: "Submit",
|
|
41
|
+
onPress: () => {
|
|
42
|
+
// Access state directly
|
|
43
|
+
console.log("Name:", name);
|
|
23
44
|
},
|
|
24
45
|
},
|
|
25
|
-
|
|
26
|
-
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<View style={{ padding: 16 }}>
|
|
53
|
+
{/*
|
|
54
|
+
👉 Form only renders what the schema describes
|
|
55
|
+
👉 No internal state, no validation, no logic
|
|
56
|
+
*/}
|
|
57
|
+
<Form schema={formSchema} />
|
|
27
58
|
</View>
|
|
28
59
|
);
|
|
29
60
|
}
|
package/package.json
CHANGED