Releases: kxcdev/kxc-melange-react-native-template
Releases · kxcdev/kxc-melange-react-native-template
v0-bc46w6a
v0-bc46w6a - the very first release
See README.md (tag: v0-bc46w6a) for more information.
Teaser
this silly game:
can be implemented with the following OCaml code (in module Accumulator_example of jsland/apps/mobile-app/melsrc/entrypoint.ml ):
let[@react.component] body ?(initialAccumulatorValue = 3) () =
let open Guikit in
let accumulator, updateAccumulator =
React.useState (constant initialAccumulatorValue) in
let mode, updateMode = React.useState (constant (`plus : [ `plus | `minus ])) in
let flip_mode = function `plus -> `minus | `minus -> `plus in
((text_str ~style:Style.accumulator
& sprintf "Accumulator = %d" accumulator;
) :: (
let mode_indicator, mode_effect = match mode with
| `plus -> "+", (+)
| `minus -> "-", Fn.flip (-)
in
let button' ?key ?onPress title =
button title ?key ?onPress
>! view ~style:[ "flexGrow", `int 1 ] in
let row ?key elems = hview elems ?key ~style:Style.row in
let action_button_row from =
(iotaf &&> row) &
((+) from) &>
fun x ->
sprintf " %s%d" mode_indicator x
|> button' ~onPress:(fun () -> updateAccumulator (mode_effect x))
in
([ action_button_row 1 3;
action_button_row 4 3;
action_button_row 7 3;
row [
button' "MOD" ~onPress:(fun () ->
updateMode flip_mode);
button' "RST" ~onPress:(fun () ->
updateAccumulator (constant initialAccumulatorValue));
button' "NEG" ~onPress:(fun () ->
updateAccumulator (( * ) (-1)));
];
] |> view) :: [
let bingo = accumulator = 0 in
text_str ~style:(Style.prompt ~bingo)
(if bingo
then "You did it! (tap RST to start over)"
else "Try to get the accumulator value to 0");
])
|> view ~style:Style.container)

