Skip to content

Commit aca4aaf

Browse files
committed
Add text event
1 parent 62c6ee6 commit aca4aaf

File tree

4 files changed

+12
-50
lines changed

4 files changed

+12
-50
lines changed

src/Flame/Native/Attribute.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
module Flame.Native.Attribute (module Exported) where
33

44
import Flame.Native.Attribute.Internal as Exported
5-
import Flame.Native.Event (EventName, ToEvent, ToRawEvent, ToMaybeEvent, ToSpecialEvent, createEvent, createEventMessage, createRawEvent, onBlur, onBlur', onCheck, onClick, onClick', onChange, onChange', onContextmenu, onContextmenu', onDblclick, onDblclick', onDrag, onDrag', onDragend, onDragend', onDragenter, onDragenter', onDragleave, onDragleave', onDragover, onDragover', onDragstart, onDragstart', onDrop, onDrop', onError, onError', onFocus, onFocus', onFocusin, onFocusin', onFocusout, onFocusout', onInput, onInput', onKeydown, onKeydown', onKeypress, onKeypress', onKeyup, onKeyup', onMousedown, onMousedown', onMouseenter, onMouseenter', onMouseleave, onMouseleave', onMousemove, onMousemove', onMouseout, onMouseout', onMouseover, onMouseover', onMouseup, onMouseup', onReset, onReset', onScroll, onScroll', onSelect, onSelect', onSubmit, onSubmit', onLoad, onLoad', onUnload, onUnload', onWheel, onWheel') as Exported
5+
import Flame.Native.Event as Exported

src/Flame/Native/Attribute/Event.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ export function createRawEvent_(name) {
2626
};
2727
}
2828

29-
export function nodeValue_(event) {
30-
if (event.target.contentEditable === true || event.target.contentEditable === "true" || event.target.contentEditable === "")
31-
return event.target.innerText;
32-
33-
return event.target.value;
34-
}
35-
3629
export function checkedValue_(event) {
3730
if (event.target.tagName === "INPUT" && (event.target.type === "checkbox" || event.target.type === "radio"))
3831
return event.target.checked;

src/Flame/Native/Attribute/Event.purs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- | Definition of react native events that can be fired from views
2-
module Flame.Native.Event (EventName, ToEvent, ToRawEvent, ToMaybeEvent, ToSpecialEvent, createEvent, createEventMessage, createRawEvent, onBlur, onBlur', onCheck, onClick, onClick', onChange, onChange', onContextmenu, onContextmenu', onDblclick, onDblclick', onDrag, onDrag', onDragend, onDragend', onDragenter, onDragenter', onDragleave, onDragleave', onDragover, onDragover', onDragstart, onDragstart', onDrop, onDrop', onError, onError', onFocus, onFocus', onFocusin, onFocusin', onFocusout, onFocusout', onInput, onInput', onKeydown, onKeydown', onKeypress, onKeypress', onKeyup, onKeyup', onMousedown, onMousedown', onMouseenter, onMouseenter', onMouseleave, onMouseleave', onMousemove, onMousemove', onMouseout, onMouseout', onLoad, onLoad', onUnload, onUnload', onMouseover, onMouseover', onMouseup, onMouseup', onReset, onReset', onScroll, onScroll', onSelect, onSelect', onSubmit, onSubmit', onWheel, onWheel') where
2+
module Flame.Native.Event where
33

44
import Prelude
55

@@ -10,6 +10,7 @@ import Effect.Uncurried (EffectFn1)
1010
import Effect.Uncurried as FU
1111
import Flame.Types (NodeData, Key)
1212
import Web.Event.Event (Event)
13+
import Unsafe.Coerce as UC
1314

1415
type EventName = String
1516

@@ -22,17 +23,13 @@ type ToMaybeEvent message = (Event → Maybe message) → NodeData message
2223
type ToSpecialEvent message t = (t message) NodeData message
2324

2425
--this way we dont need to worry about every possible element type
25-
foreign import nodeValue_ EffectFn1 Event String
2626
foreign import checkedValue_ EffectFn1 Event Boolean
2727
foreign import preventDefault_ EffectFn1 Event Unit
2828
foreign import key_ EffectFn1 Event Key
2929
foreign import selection_ EffectFn1 Event String
3030
foreign import createEvent_ message. EventName message (NodeData message)
3131
foreign import createRawEvent_ message. EventName (Event Effect (Maybe message)) (NodeData message)
3232

33-
nodeValue Event Effect String
34-
nodeValue = FU.runEffectFn1 nodeValue_
35-
3633
checkedValue Event Effect Boolean
3734
checkedValue = FU.runEffectFn1 checkedValue_
3835

@@ -89,12 +86,9 @@ onChange' = createEventMessage "change"
8986

9087
-- | This event fires when the value of an input, select, textarea, contenteditable or designMode on elements changes
9188
onInput message. ToSpecialEvent message String
92-
onInput constructor = createRawEvent "input" handler
89+
onInput constructor = createEventMessage "onChangeText" handler
9390
where
94-
handler event = Just <<< constructor <$> nodeValue event
95-
96-
onInput' message. ToRawEvent message
97-
onInput' = createEventMessage "input"
91+
handler = constructor <<< UC.unsafeCoerce
9892

9993
-- | Helper for `input` event of checkboxes and radios
10094
onCheck message. ToSpecialEvent message Boolean
@@ -146,30 +140,9 @@ onReset = createEvent "reset"
146140
onReset' message. ToRawEvent message
147141
onReset' = createEventMessage "reset"
148142

149-
onKeydown message. ToSpecialEvent message (Tuple Key String)
150-
onKeydown constructor = createRawEvent "keydown" (keyInput constructor)
151-
152-
onKeydown' message. ToRawEvent message
153-
onKeydown' = createEventMessage "keydown"
154-
155-
onKeypress message. ToSpecialEvent message (Tuple Key String)
156-
onKeypress constructor = createRawEvent "keypress" (keyInput constructor)
157-
158-
onKeypress' message. ToRawEvent message
159-
onKeypress' = createEventMessage "keypress"
160-
161-
onKeyup message. ToSpecialEvent message (Tuple Key String)
162-
onKeyup constructor = createRawEvent "keyup" (keyInput constructor)
163-
164143
onKeyup' message. ToRawEvent message
165144
onKeyup' = createEventMessage "keyup"
166145

167-
keyInput message. (Tuple Key String message) Event Effect (Maybe message)
168-
keyInput constructor event = do
169-
down ← key event
170-
value ← nodeValue event
171-
pure <<< Just <<< constructor $ Tuple down value
172-
173146
onContextmenu message. ToEvent message
174147
onContextmenu = createEvent "contextmenu"
175148

src/Flame/Native/Attribute/Internal.purs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,12 @@ else instance DF.Foldable f ⇒ ToStyleList (f (Tuple String String)) where
5353
toStyleList = FO.fromFoldable
5454

5555
-- | Sets a react native property
56-
foreign import createProperty message. String String NodeData message
56+
foreign import createProperty message v. String v NodeData message
5757

5858
foreign import createClass message. Array String NodeData message
5959

6060
foreign import createStyle message. Object String NodeData message
6161

62-
booleanToFalsyString Boolean String
63-
booleanToFalsyString =
64-
case _ of
65-
true"true"
66-
false""
67-
6862
class' a b. ToClassList b b NodeData a
6963
class' = createClass <<< map caseify <<< to
7064

@@ -139,11 +133,13 @@ autocomplete ∷ ToStringAttribute
139133
autocomplete = createProperty "autocomplete"
140134

141135
checked ToBooleanAttribute
142-
checked = createProperty "checked" <<< booleanToFalsyString
143-
136+
checked = createProperty "checked"
144137

145138
disabled ToBooleanAttribute
146-
disabled = createProperty "disabled" <<< booleanToFalsyString
139+
disabled = createProperty "disabled"
147140

148141
selected ToBooleanAttribute
149-
selected = createProperty "selected" <<< booleanToFalsyString
142+
selected = createProperty "selected"
143+
144+
keyboardType :: ToStringAttribute
145+
keyboardType = createProperty "keyboardType"

0 commit comments

Comments
 (0)