git.iko.soy/rowtype-yoga/purescript-yoga-react-native
on main help sign in
WIP: React Native bindings development
33fd463Mark
example-macos/src/Demo/AiMl.purs+1−1
@@ -94,7 +94,7 @@ naturalLanguageDemo = component "NaturalLanguageDemo" \dp -> React.do
94 , nativeTextField
94 , nativeTextField
95 { text: txt
95 { text: txt
96 , placeholder: "Enter text to analyze..."
96 , placeholder: "Enter text to analyze..."
97− , onChangeText: E.onString "text" setTxt
97+ , onChangeText: setTxt
98 , style: Style.style { height: 24.0 } <> tw "mb-2"
98 , style: Style.style { height: 24.0 } <> tw "mb-2"
99 }
99 }
100 , view { style: tw "flex-row items-center mb-2" }
100 , view { style: tw "flex-row items-center mb-2" }
example-macos/src/Demo/Chat.purs+2−2
@@ -361,8 +361,8 @@ chatDemo = component "ChatDemo" \dp -> React.do
361 , placeholder: "Message..."
361 , placeholder: "Message..."
362 , search: false
362 , search: false
363 , rounded: true
363 , rounded: true
364− , onChangeText: E.onString "text" \t -> setInputText (replaceEmoji t)
364+ , onChangeText: \t -> setInputText (replaceEmoji t)
365− , onSubmit: E.onString "text" \t -> sendMessage rid t
365+ , onSubmit: \t -> sendMessage rid t
366 , style: tw "flex-1" <> Style.style { height: 28.0 }
366 , style: tw "flex-1" <> Style.style { height: 28.0 }
367 }
367 }
368 , nativeButton
368 , nativeButton
example-macos/src/Demo/SystemServices.purs+1−1
@@ -189,7 +189,7 @@ speechDemo = component "SpeechDemo" \dp -> React.do
189 , nativeTextField
189 , nativeTextField
190 { text: txt
190 { text: txt
191 , placeholder: "Text to speak..."
191 , placeholder: "Text to speak..."
192− , onChangeText: E.onString "text" setTxt
192+ , onChangeText: setTxt
193 , style: Style.style { height: 24.0 } <> tw "mb-2"
193 , style: Style.style { height: 24.0 } <> tw "mb-2"
194 }
194 }
195 , view { style: tw "flex-row items-center mb-4" }
195 , view { style: tw "flex-row items-center mb-4" }
example-macos/src/Demo/TextEditing.purs+1−1
@@ -24,7 +24,7 @@ textFieldDemo = component "TextFieldDemo" \dp -> React.do
24 { placeholder: "Type something..."
24 { placeholder: "Type something..."
25 , search: true
25 , search: true
26 , text: txt
26 , text: txt
27− , onChangeText: E.onString "text" setTxt
27+ , onChangeText: setTxt
28 , style: Style.style { height: 24.0 }
28 , style: Style.style { height: 24.0 }
29 }
29 }
30 , if txt == "" then mempty
30 , if txt == "" then mempty
example-macos/src/Demo/WebBrowser.purs+2−2
@@ -25,8 +25,8 @@ webViewDemo = component "WebViewDemo" \dp -> React.do
25 { text: urlBar
25 { text: urlBar
26 , placeholder: "Enter URL..."
26 , placeholder: "Enter URL..."
27 , search: false
27 , search: false
28− , onChangeText: E.onString "text" setUrlBar
28+ , onChangeText: setUrlBar
29− , onSubmit: E.onString "text" setUrl
29+ , onSubmit: setUrl
30 , style: Style.style { height: 24.0, marginBottom: 8.0 }
30 , style: Style.style { height: 24.0, marginBottom: 8.0 }
31 }
31 }
32 , nativeWebView
32 , nativeWebView
src/Yoga/React/Native/MacOS/TextField.js+14−1
@@ -1,2 +1,15 @@
1+import React from "react";
1import { requireNativeComponent } from "react-native";
2import { requireNativeComponent } from "react-native";
3+
4+const NativeTextField = requireNativeComponent("NativeTextField");
5+
2−export const textFieldImpl = requireNativeComponent("NativeTextField");
6+export const textFieldImpl = React.forwardRef((props, ref) => {
7+ const nativeProps = { ...props };
8+ if (typeof props.onChangeText === "function") {
9+ nativeProps.onChangeText = (e) => props.onChangeText(e.nativeEvent.text)();
10+ }
11+ if (typeof props.onSubmit === "function") {
12+ nativeProps.onSubmit = (e) => props.onSubmit(e.nativeEvent.text)();
13+ }
14+ return React.createElement(NativeTextField, { ...nativeProps, ref });
15+});
src/Yoga/React/Native/MacOS/TextField.purs+3−3
@@ -1,7 +1,7 @@
1module Yoga.React.Native.MacOS.TextField (nativeTextField, NativeTextFieldAttributes) where
1module Yoga.React.Native.MacOS.TextField (nativeTextField, NativeTextFieldAttributes) where
2
2
3+import Effect (Effect)
3import React.Basic (ReactComponent)
4import React.Basic (ReactComponent)
4−import React.Basic.Events (EventHandler)
5import Yoga.React.Native.Attributes (BaseAttributes)
5import Yoga.React.Native.Attributes (BaseAttributes)
6import Yoga.React.Native.Internal (FFINativeComponent_, createNativeElement_)
6import Yoga.React.Native.Internal (FFINativeComponent_, createNativeElement_)
7
7
@@ -16,6 +16,6 @@ type NativeTextFieldAttributes = BaseAttributes
16 , secure :: Boolean
16 , secure :: Boolean
17 , search :: Boolean
17 , search :: Boolean
18 , rounded :: Boolean
18 , rounded :: Boolean
19− , onChangeText :: EventHandler
19+ , onChangeText :: String -> Effect Unit
20− , onSubmit :: EventHandler
20+ , onSubmit :: String -> Effect Unit
21 )
21 )