fable-compiler / fable-react

Fable bindings and helpers for React and React Native
MIT License
275 stars 66 forks source link

Add React Native signature pad #26

Open forki opened 7 years ago

forki commented 7 years ago

@alfonsogarciacaro promised to add this to react native bindings once things moved to 1.0 :P

open Fable.Core.JsInterop
module R = Fable.Helpers.React

type RCom = Fable.Import.React.ComponentClass<obj>

let SignaturePad: RCom = importDefault "react-native-signature-pad"

/// Opens a signature pad with callbacks for onError and onChange
let signaturePad (props:Fable.Helpers.ReactNative.Props.IStyle list) (onError:exn -> unit) (onChange:string -> unit) : React.ReactElement =
    let onChange (o:obj) = onChange(o?base64DataUrl |> unbox)
    let pad =
        createObj
            [ "style" ==> props
            "onError" ==> onError
            "onChange" ==> onChange ]
        |> unbox

    R.from SignaturePad pad []