-
Notifications
You must be signed in to change notification settings - Fork 25
/
Modal.purs
74 lines (64 loc) · 2.1 KB
/
Modal.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module ReactNative.Components.Modal (
AnimationType
, OnRequestClose
, Orientation
, animationType
, modal'
, modal_
, modal
) where
import Prelude
import Data.Record.Class (class Subrow)
import React (ReactElement)
import ReactNative.Events (EventHandler, UnitEventHandler)
import ReactNative.Unsafe.ApplyProps (unsafeApplyProps)
import ReactNative.Unsafe.Components (modalU)
newtype AnimationType = AnimationType String
animationType :: {
slide :: AnimationType
, fade :: AnimationType
, none :: AnimationType
}
animationType = {
slide: AnimationType "slide"
, fade: AnimationType "fade"
, none: AnimationType "none"
}
newtype Orientation = Orientation String
orientationType :: {
portrait :: Orientation
, landscape :: Orientation
}
orientationType = {
portrait: Orientation "portrait"
, landscape: Orientation "landscape"
}
type OnRequestClose eff = UnitEventHandler eff
type ModalPropsO a eff = (
animationType :: AnimationType
, onShow :: UnitEventHandler eff
, transparent :: Boolean
, visible :: Boolean
, android :: {
hardwareAccelerated :: Boolean
, onRequestClose :: OnRequestClose eff
}
, ios :: {
onOrientationChange :: EventHandler eff Orientation
, supportedOrientations :: Array Orientation
}
)
modal' :: forall a eff o
. Subrow o (ModalPropsO a eff)
=> {|o} -> Array ReactElement -> ReactElement
modal' = modalU <<< unsafeApplyProps
-- On request is required *for android*. Least nasty solution is to require it, and provide a default for iOS
-- https://github.com/facebook/react-native/commit/ce81f8b35af8d273072583d369594d4f5fd6d696
modal_ :: forall eff. OnRequestClose eff -> Array ReactElement -> ReactElement
modal_ orc = modalU {onRequestClose: orc}
modalIOS_ :: Array ReactElement -> ReactElement
modalIOS_ = modalU {}
modal :: forall eff. Boolean -> AnimationType -> OnRequestClose eff -> Array ReactElement -> ReactElement
modal v at orc = modalU {visible: v, animationType: at, onRequestClose: orc}
modalIOS :: Boolean -> AnimationType -> Array ReactElement -> ReactElement
modalIOS v at = modalU {visible: v, animationType: at}