1
1
import React , { Component } from 'react' ;
2
2
import PropTypes from 'prop-types'
3
- import { StyleSheet , Image , Text , View , Platform , ActionSheetIOS , UIManager , findNodeHandle } from 'react-native' ;
4
- import { MoreButton } from './Buttons'
3
+ import { NoteType } from './propTypes'
4
+ import {
5
+ StyleSheet ,
6
+ Image ,
7
+ Text ,
8
+ View ,
9
+ Platform ,
10
+ ActionSheetIOS ,
11
+ UIManager ,
12
+ findNodeHandle
13
+ } from 'react-native' ;
14
+ import { MenuButton } from './Buttons'
15
+ import { MAX_NOTE_HEIGHT , NOTE_AVATAR_SIZE } from '../constants'
5
16
6
17
const styles = StyleSheet . create ( {
7
18
note : {
@@ -10,7 +21,7 @@ const styles = StyleSheet.create({
10
21
borderColor : 'gray' ,
11
22
paddingVertical : 20 ,
12
23
paddingHorizontal : 15 ,
13
- maxHeight : 150
24
+ maxHeight : MAX_NOTE_HEIGHT
14
25
} ,
15
26
16
27
title : {
@@ -20,9 +31,9 @@ const styles = StyleSheet.create({
20
31
} ,
21
32
22
33
avatar : {
23
- width : 50 ,
24
- height : 50 ,
25
- borderRadius : 25
34
+ width : NOTE_AVATAR_SIZE ,
35
+ height : NOTE_AVATAR_SIZE ,
36
+ borderRadius : NOTE_AVATAR_SIZE / 2
26
37
} ,
27
38
28
39
info : {
@@ -46,13 +57,7 @@ const styles = StyleSheet.create({
46
57
47
58
export class NoteListItem extends Component {
48
59
static propTypes = {
49
- note : PropTypes . shape ( {
50
- userName : PropTypes . string ,
51
- avatar : PropTypes . any ,
52
- editTime : PropTypes . string ,
53
- text : PropTypes . string
54
- } ) ,
55
-
60
+ note : NoteType ,
56
61
onRemoveNote : PropTypes . func ,
57
62
onNavigateNote : PropTypes . func ,
58
63
}
@@ -67,22 +72,30 @@ export class NoteListItem extends Component {
67
72
}
68
73
}
69
74
70
- showActionSheet = options => {
71
- ActionSheetIOS . showActionSheetWithOptions ( { options, destructiveButtonIndex : 1 } , this . onPressMenu )
75
+ showActionSheet = ( ) => {
76
+ ActionSheetIOS . showActionSheetWithOptions ( {
77
+ options : [ 'Edit' , 'Delete' , 'Cancel' ] ,
78
+ destructiveButtonIndex : 1 ,
79
+ cancelButtonIndex : 2
80
+ } ,
81
+ this . onPressMenu
82
+ )
72
83
}
73
84
74
- showPopupMenu = options => {
85
+ showPopupMenu = ( ) => {
75
86
const button = findNodeHandle ( this . _buttonRef )
76
- UIManager . showPopupMenu ( button , options , ( e ) => console . error ( e ) , ( e , i ) => this . onPressMenu ( i ) )
87
+ UIManager . showPopupMenu (
88
+ button ,
89
+ [ 'Edit' , 'Delete' ] ,
90
+ e => console . error ( e ) ,
91
+ ( e , i ) => this . onPressMenu ( i )
92
+ )
77
93
}
78
94
79
95
onOpenMenu = ( ) => {
80
- const options = [ 'Edit' , 'Delete' ]
81
-
82
- Platform . select ( {
83
- ios : this . showActionSheet ( options ) ,
84
- android : this . showPopupMenu ( options )
85
- } )
96
+ Platform . OS === 'ios' ?
97
+ this . showActionSheet ( ) :
98
+ this . showPopupMenu ( )
86
99
}
87
100
88
101
render ( ) {
@@ -98,7 +111,11 @@ export class NoteListItem extends Component {
98
111
</ View >
99
112
</ View >
100
113
< Text style = { styles . name } > { text } </ Text >
101
- < MoreButton ref = { ref => this . _buttonRef = ref } style = { styles . button } onPress = { this . onOpenMenu } />
114
+ < MenuButton
115
+ style = { styles . button }
116
+ ref = { ref => this . _buttonRef = ref }
117
+ onPress = { this . onOpenMenu }
118
+ />
102
119
</ View >
103
120
)
104
121
}
0 commit comments