hariroshan / elm-native / Native.Event

Events listeners for Nativescript UI Elements

Events

on : String -> Json.Decode.Decoder msg -> Html.Attribute msg

Allows you to build your own events and decoders

onBlur : msg -> Html.Attribute msg

Listen for blur

onBusyChange : msg -> Html.Attribute msg

Listen for busyChange

onDateChange : ({ day : Basics.Int, month : Basics.Int, year : Basics.Int } -> msg) -> Html.Attribute msg

Listen for dateChange

onEventWith : String -> EventOptions -> Json.Decode.Decoder msg -> Html.Attribute msg

Method values are kept under {custom: {[methodName]: value}} We will improve this in future

For example:

Event.onEventWithMethodCalls "touch"
    { methodCalls = [ "getX", "getY" ]
    , setters = []
    , getters = []
    }
    (D.map2 Tuple.pair
        (D.at [ "custom", "getX" ] D.float)
        (D.at [ "custom", "getY" ] D.float)
        |> D.map Msg
    )

onFocus : msg -> Html.Attribute msg

Listen for focus

onItemTap : (Basics.Int -> msg) -> Html.Attribute msg

Listen for itemTap in listView

onLoaded : msg -> Html.Attribute msg

Listen for loaded

onReturnPress : msg -> Html.Attribute msg

Listen for returnPress

onSelectedIndexChange : (Basics.Int -> msg) -> Html.Attribute msg

Listens for selectedIndexChange

onTap : msg -> Html.Attribute msg

Listen for tap

onTextChange : (String -> msg) -> Html.Attribute msg

Listens for textChange event

onUnloaded : msg -> Html.Attribute msg

Listen for unloaded

onValueChange : (Basics.Float -> msg) -> Html.Attribute msg

Listen for valueChange

Decoder

decodeAttribute : String -> Json.Decode.Decoder a -> Json.Decode.Decoder a

Allows you to decode attributes from nativescript object

Usage:

listViewWithSingleTemplate
    [ items listViewModel ]
    [ button
        [ bindAttributeWithExpression "item-id" "$value.id"
        , on "tap" (Event.decodeAttribute "itemId" D.string |> D.map ItemTap)
        ]
        []
    ]