forked from doolse/purescript-reactnative-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovieCell.purs
More file actions
81 lines (77 loc) · 2.51 KB
/
MovieCell.purs
File metadata and controls
81 lines (77 loc) · 2.51 KB
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
75
76
77
78
79
80
81
module Movies.MovieCell where
import Prelude
import Movie.Data (Movie, getImageSource, getStyleFromScore, getTextFromScore)
import React (ReactElement)
import ReactNative.Components (iosProps)
import ReactNative.Components.Image (image)
import ReactNative.Components.Text (text, text', textElem, texts')
import ReactNative.Components.Touchable (touchableHighlight)
import ReactNative.Components.TouchableNativeFeedback (touchableNativeFeedback)
import ReactNative.Components.View (view)
import ReactNative.Events (EventHandler, TouchEvent)
import ReactNative.Platform (platformOS, Platform(..))
import ReactNative.PropTypes (center)
import ReactNative.PropTypes.Color (rgba, rgbi, white)
import ReactNative.Styles (Styles, backgroundColor, flex, hairlineWidth, height, marginBottom, marginLeft, marginRight, padding, staticStyles, width)
import ReactNative.Styles.Flex (alignItems, flexDirection, row)
import ReactNative.Styles.Text (color, fontSize, fontWeight, weight500)
type Props = {
key :: String
, movie :: Movie
, onSelect :: EventHandler TouchEvent
}
movieCell :: Movie -> {onSelect::EventHandler TouchEvent} -> ReactElement
movieCell m p =
let score = m.score
touchableView :: Platform -> EventHandler TouchEvent -> ReactElement -> ReactElement
touchableView IOS = touchableHighlight
touchableView Android = touchableNativeFeedback
in (touchableView platformOS) p.onSelect $ view sheet.row [
image sheet.cellImage (getImageSource m)
, view sheet.textContainer [
text' {style:sheet.movieTitle, numberOfLines:2, ios:iosProps {allowFontScaling:true}} m.title
, texts' {style:sheet.movieYear, numberOfLines:1} [
textElem $ m.year <> " "
, text (getStyleFromScore score) $ "Critics " <> getTextFromScore score
]
]
]
sheet :: { textContainer :: Styles
, movieTitle :: Styles
, movieYear :: Styles
, row :: Styles
, cellImage :: Styles
, cellBorder :: Styles
}
sheet = {
textContainer: staticStyles [
flex 1
],
movieTitle: staticStyles [
flex 1,
fontSize 16,
fontWeight weight500,
marginBottom 2
],
movieYear: staticStyles [
color $ rgbi 0x999999,
fontSize 12
],
row: staticStyles [
alignItems center,
backgroundColor white,
flexDirection row,
padding 5
],
cellImage: staticStyles [
backgroundColor $ rgbi 0xdddddd,
height 93,
marginRight 10,
width 60
],
cellBorder: staticStyles [
backgroundColor $ rgba 0 0 0 0.1,
height hairlineWidth,
marginLeft 4
]
}