forked from rescript-react-native/rescript-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsExample.re
More file actions
85 lines (75 loc) · 1.93 KB
/
SettingsExample.re
File metadata and controls
85 lines (75 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
open BsReactNative;
open Utils;
let exampleType = Multiple;
let displayName = "SettingsExample";
let title = "SettingsExample";
let description = "SettingsExample (iOS only)";
module SetExample = {
type action =
| SetVersion(string);
type state = {version: string};
let component = ReasonReact.reducerComponent("SetExample");
let make = _children => {
...component,
initialState: () => {version: "1.0"},
reducer: (action: action, _state: state) =>
switch (action) {
| SetVersion(version) => ReasonReact.Update({version: version})
},
didMount: _self => {
let _ =
Settings.watchKeys(
["name_preference"],
_ => {
Js.log("New value set");
();
},
);
let id =
Settings.watchKeys(["name_preference"], _ =>
Js.log("New value set 2")
);
Settings.clearWatch(id);
},
render: self =>
<View>
<TextInput
value={self.state.version}
onChangeText={text => self.send(SetVersion(text))}
/>
<Button
onPress={
() => {
let settings = Js.Dict.empty();
Js.Dict.set(settings, "version_preference", self.state.version);
Settings.set(settings);
}
}
title="Set version"
accessibilityLabel="See an informative alert"
/>
</View>,
};
};
let examples: array(Example.t) = [|
{
title: "Set",
description: Some("Set Settings values"),
render: () => <SetExample />,
},
{
title: "Get",
description: Some("Get Settings value"),
render: () =>
<Button
onPress={
() => {
let version = Settings.get("version_preference");
Alert.alert(~title="version -> " ++ version, ());
}
}
title="Get version"
accessibilityLabel="See an informative alert"
/>,
},
|];