ohanhi / elm-native-ui

[CLOSED] Experiment: mobile apps in Elm using React Native.
BSD 3-Clause "New" or "Revised" License
1.54k stars 76 forks source link

Add Alert and PushNotificationIOS modules #87

Closed iancanderson closed 6 years ago

iancanderson commented 6 years ago

This adds an Alert module for showing system dialogs, as well as a PushNotificationIOS module for handling push notifications on.. iOS!

See Purple Train PR for complete real-world usage examples: https://github.com/thoughtbot/PurpleTrainElm/pull/71

Here are some example snippets:

-- Shows dialog with two buttons
-- App receives `ReceivePushPrePromptResponse` message when user taps a button,
-- with a `Result` containing a boolean that corresponds to the value of the tapped button
Task.attempt ReceivePushPrePromptResponse <|
    NativeUi.alert
        "This is what it sounds like when trains cry"
        "Purple Train can send you notifications when your trains are cancelled!"
        [ { text = "Not Now", value = False }
        , { text = "Give Access", value = True }
        ]
-- Handling result from ReceivePushPrePromptResponse in the update function:
case result of
    Ok True ->
        -- register function kicks off a task that shows the system permission dialog
        -- Calls update with the ReceivePushToken message with a Result of either:
        -- Ok (with the device push token) or Err (with the registration error)
        Task.attempt ReceivePushToken PushNotificationIOS.register

    _ ->
        Cmd.none
iancanderson commented 6 years ago

@ohanhi @eeue56 Thanks for giving this PR new life! I've made the suggested changes. If it looks good, let me know so I can squash and get this merged 👍

ohanhi commented 6 years ago

No need to squash commits. I'll merge this as is.