git.iko.soy/rowtype-yoga/purescript-yoga-react-native
on main help sign in
WIP: React Native bindings development
commitded9ba0a269ed5d97aeb6e509f7315fa6af34f7f authorMark <mark.eibes@gmail.com> dateMon 16 Feb 2026, 22:52 (8 months ago) parent401dc03
8 files changed+55−35
docs/src/Docs/Pages/Overlays.purs+10−12 docs/src/Docs/Pages/SystemServices.purs+8−5 example-macos/src/Demo/Overlays.purs+9−7 example-macos/src/Demo/SystemServices.purs+1−1 src/Yoga/React/Native/MacOS/Menu.js+1−1 src/Yoga/React/Native/MacOS/Menu.purs+10−4 src/Yoga/React/Native/MacOS/UserNotification.js+1−1 src/Yoga/React/Native/MacOS/UserNotification.purs+15−4
docs/src/Docs/Pages/Overlays.purs+10−12
@@ -90,17 +90,15 @@ nativeContextMenu
9090
9191menu :: Nut
9292menu = L.componentDoc "macosShowMenu" "Yoga.React.Native.MacOS.Menu (macosShowMenu)"
93− """-- Imperative function with 2 positional args
94−macosShowMenu
95− [ { title: "New", id: "new" }
96− , { title: "Open", id: "open" }
97− ]
98− (\selectedId -> log selectedId)
99− # liftEffect"""
100− [ D.p [ DA.klass_ "text-sm text-gray-400 mt-2" ]
101− [ D.text_ "Signature: Array MenuItem -> (String -> Effect Unit) -> Effect Unit" ]
102− , propsTable
103− [ { name: "arg 1", type_: "Array MenuItem", description: "Menu items ({ title :: String, id :: String })" }
104− , { name: "arg 2", type_: "String -> Effect Unit", description: "Callback receiving the selected item id" }
93+ """macosShowMenu
94+ { items:
95+ [ { title: "New", id: "new" }
96+ , { title: "Open", id: "open" }
97+ ]
98+ , onSelectItem: \selectedId -> log selectedId
99+ }"""
100+ [ propsTable
101+ [ { name: "items", type_: "Array MenuItem", description: "Menu items ({ title, id })" }
102+ , { name: "onSelectItem", type_: "String -> Effect Unit", description: "Callback receiving the selected item id" }
105103 ]
106104 ]
docs/src/Docs/Pages/SystemServices.purs+8−5
@@ -44,11 +44,14 @@ macosShare ["Check out this library!", "https://github.com/rowtype-yoga/purescri
4444
4545notification :: Nut
4646notification = L.componentDoc "macosNotify" "Yoga.React.Native.MacOS.UserNotification (macosNotify)"
47− """-- Takes 2 positional String args: title and body
48−macosNotify "Build Complete" "Your project compiled successfully."
49− # liftEffect"""
50− [ D.p [ DA.klass_ "text-sm text-gray-400 mt-2" ]
51− [ D.text_ "Signature: String -> String -> Effect Unit" ]
47+ """macosNotify
48+ { title: "Build Complete"
49+ , body: "Your project compiled successfully."
50+ }"""
51+ [ propsTable
52+ [ { name: "title", type_: "String", description: "Notification title" }
53+ , { name: "body", type_: "String", description: "Notification body text" }
54+ ]
5255 ]
5356
5457sound :: Nut
example-macos/src/Demo/Overlays.purs+9−7
@@ -137,13 +137,15 @@ menuDemo = component "MenuDemo" \dp -> React.do
137137 , bezelStyle: T.push
138138 , onPress: handler_
139139 ( macosShowMenu
140− [ { title: "New File", id: "new" }
141− , { title: "Open...", id: "open" }
142− , { title: "-", id: "sep" }
143− , { title: "Save", id: "save" }
144− , { title: "Save As...", id: "saveAs" }
145− ]
146− \itemId -> setResult ("Menu: " <> itemId)
140+ { items:
141+ [ { title: "New File", id: "new" }
142+ , { title: "Open...", id: "open" }
143+ , { title: "-", id: "sep" }
144+ , { title: "Save", id: "save" }
145+ , { title: "Save As...", id: "saveAs" }
146+ ]
147+ , onSelectItem: \itemId -> setResult ("Menu: " <> itemId)
148+ }
147149 )
148150 , style: Style.style { height: 24.0, width: 120.0 }
149151 }
example-macos/src/Demo/SystemServices.purs+1−1
@@ -70,7 +70,7 @@ notificationsDemo = component "NotificationsDemo" \dp -> pure do
7070 , nativeButton
7171 { title: "Send Notification"
7272 , bezelStyle: T.push
73− , onPress: handler_ (macosNotify "PureScript" "Hello from React Native macOS!")
73+ , onPress: handler_ (macosNotify { title: "PureScript", body: "Hello from React Native macOS!" })
7474 , style: Style.style { height: 24.0, width: 160.0 } <> tw "mb-2"
7575 }
7676 ]
src/Yoga/React/Native/MacOS/Menu.js+1−1
@@ -1,6 +1,6 @@
11import { NativeModules, Platform } from "react-native";
22
3−export const showMenuImpl = (items, callback) => {
3+export const showMenuImpl = ({ items, onSelectItem: callback }) => {
44 if (Platform.OS !== "macos") return;
55 const mod = NativeModules.MacOSMenuModule;
66 if (mod && mod.show) {
src/Yoga/React/Native/MacOS/Menu.purs+10−4
@@ -1,19 +1,25 @@
11module Yoga.React.Native.MacOS.Menu
22 ( macosShowMenu
33 , MenuItem
4+ , MenuProps
45 ) where
56
67import Prelude
78
89import Effect (Effect)
9−import Effect.Uncurried (EffectFn2, runEffectFn2)
10+import Effect.Uncurried (EffectFn1, runEffectFn1)
1011
1112type MenuItem =
1213 { title :: String
1314 , id :: String
1415 }
1516
16−foreign import showMenuImpl :: EffectFn2 (Array MenuItem) (String -> Effect Unit) Unit
17+type MenuProps =
18+ { items :: Array MenuItem
19+ , onSelectItem :: String -> Effect Unit
20+ }
21+
22+foreign import showMenuImpl :: EffectFn1 MenuProps Unit
1723
18−macosShowMenu :: Array MenuItem -> (String -> Effect Unit) -> Effect Unit
19−macosShowMenu = runEffectFn2 showMenuImpl
24+macosShowMenu :: MenuProps -> Effect Unit
25+macosShowMenu = runEffectFn1 showMenuImpl
src/Yoga/React/Native/MacOS/UserNotification.js+1−1
@@ -1,6 +1,6 @@
11import { NativeModules, Platform } from "react-native";
22
3−export const notifyImpl = (title, body) => {
3+export const notifyImpl = ({ title = "", body = "" }) => {
44 if (Platform.OS !== "macos") return;
55 const mod = NativeModules.MacOSNotificationModule;
66 if (mod && mod.notify) {
src/Yoga/React/Native/MacOS/UserNotification.purs+15−4
@@ -1,13 +1,24 @@
11module Yoga.React.Native.MacOS.UserNotification
22 ( macosNotify
3+ , NotifyProps
34 ) where
45
56import Prelude
67
78import Effect (Effect)
8−import Effect.Uncurried (EffectFn2, runEffectFn2)
9+import Effect.Uncurried (EffectFn1, runEffectFn1)
10+import Prim.Row (class Union)
911
10−foreign import notifyImpl :: EffectFn2 String String Unit
12+type NotifyProps =
13+ ( title :: String
14+ , body :: String
15+ )
1116
12−macosNotify :: String -> String -> Effect Unit
13−macosNotify = runEffectFn2 notifyImpl
17+foreign import notifyImpl :: EffectFn1 (Record NotifyProps) Unit
18+
19+macosNotify
20+ :: forall given missing
21+ . Union given missing NotifyProps
22+ => { | given }
23+ -> Effect Unit
24+macosNotify = runEffectFn1 notifyImpl