@@ -28,7 +28,9 @@ const TOP_OFFSET = 20;
2828class ActionSheet extends React . Component {
2929 static defaultProps = {
3030 animated : true ,
31- mode : 'default'
31+ mode : 'default' ,
32+ cancelText : 'Cancel' ,
33+ destructive : false
3234 }
3335
3436 static propTypes = {
@@ -39,7 +41,10 @@ class ActionSheet extends React.Component {
3941 'default' , // default
4042 'list'
4143 ] ) ,
42- title : React . PropTypes . any
44+ title : React . PropTypes . any ,
45+ cancelText : React . PropTypes . string ,
46+ onCancelPress : React . PropTypes . func ,
47+ destructive : React . PropTypes . bool
4348 }
4449
4550 constructor ( props ) {
@@ -121,6 +126,10 @@ class ActionSheet extends React.Component {
121126 this . animateToValue ( 0 , this . props . onOpen ) ;
122127 }
123128
129+ handleCancelOnPress = ( ) => {
130+ this . close ( this . props . onCancelPress ) ;
131+ }
132+
124133 renderActionItems ( ) {
125134 const children = React . Children . toArray ( this . props . children ) ;
126135
@@ -134,6 +143,14 @@ class ActionSheet extends React.Component {
134143 children . unshift ( title ) ;
135144 }
136145
146+ if ( this . props . cancelText ) {
147+ children . push (
148+ < ActionItem backgroundColor = { theme . color . light } onPress = { this . handleCancelOnPress } >
149+ < Text style = { styles . cancelText } > { this . props . cancelText . toUpperCase ( ) } </ Text >
150+ </ ActionItem >
151+ ) ;
152+ }
153+
137154 return children . map ( ( item , i ) => {
138155
139156 const isFirstChild = i === 0 ;
@@ -155,8 +172,6 @@ class ActionSheet extends React.Component {
155172 </ View >
156173 ) ;
157174 } else {
158- const title = item . props . destructive ? < Text style = { styles . actionDestructiveText } > { item . props . title . toUpperCase ( ) } </ Text > : item . props . title ;
159-
160175 const itemOnPress = ( ) => {
161176 this . close ( item . props . onPress ) ;
162177 } ;
@@ -165,13 +180,13 @@ class ActionSheet extends React.Component {
165180 < View key = { 'action-item-' + i } >
166181 < Cell
167182 { ...item . props }
168- title = { title }
169- onPress = { item . props . destructive || item . props . onPress ? itemOnPress : null }
183+ onPress = { item . props . onPress && itemOnPress }
170184 style = { [
171- item . props . destructive ? styles . actionDestructive : item . props . backgroundColor && { backgroundColor : item . props . backgroundColor } ,
185+ item . props . backgroundColor && { backgroundColor : item . props . backgroundColor } ,
172186 isFirstChild ? styles . borderTopRadius : null ,
173187 isLastChild ? styles . borderBottomRadius : null
174188 ] }
189+ tintColor = { item . props . destructive && theme . color . danger }
175190 />
176191 { separator }
177192 </ View >
@@ -232,15 +247,14 @@ const styles = StyleSheet.create({
232247 backgroundColor : theme . color . white
233248 } ,
234249
235- actionDestructive : {
250+ cancelContainer : {
236251 backgroundColor : theme . color . light
237252 } ,
238- actionDestructiveText : {
253+ cancelText : {
239254 textAlign : 'center' ,
240255 fontSize : theme . font . small ,
241256 fontWeight : '600' ,
242- color : theme . color . muted ,
243- flex : 1
257+ color : theme . color . muted
244258 } ,
245259 borderTopRadius : {
246260 borderTopRightRadius : theme . radius ,
0 commit comments