77 Animated ,
88 StatusBar ,
99 PanResponder ,
10+ Image ,
11+ Text ,
1012} from 'react-native' ;
1113import PropTypes from 'prop-types' ;
1214import {
@@ -18,10 +20,7 @@ import {
1820 HEIGHT ,
1921 getDefaultStatusBarStyle ,
2022 getDefaultStatusBarBackgroundColor ,
21- } from './constants' ;
22- import TextView from './TextView' ;
23- import ImageView from './imageview' ;
24- import CancelButton from './CancelButton' ;
23+ } from './Utils' ;
2524import Queue from './Queue' ;
2625
2726export default class DropdownAlert extends Component {
@@ -129,7 +128,6 @@ export default class DropdownAlert extends Component {
129128 panResponderEnabled : true ,
130129 wrapperStyle : null ,
131130 containerStyle : {
132- padding : 16 ,
133131 flexDirection : 'row' ,
134132 backgroundColor : '#202020' ,
135133 } ,
@@ -152,24 +150,24 @@ export default class DropdownAlert extends Component {
152150 backgroundColor : 'transparent' ,
153151 } ,
154152 imageStyle : {
155- padding : 8 ,
156153 width : DEFAULT_IMAGE_DIMENSIONS ,
157154 height : DEFAULT_IMAGE_DIMENSIONS ,
158155 alignSelf : 'center' ,
159156 } ,
160157 cancelBtnImageStyle : {
161- padding : 8 ,
162158 width : DEFAULT_IMAGE_DIMENSIONS ,
163159 height : DEFAULT_IMAGE_DIMENSIONS ,
160+ } ,
161+ cancelBtnStyle : {
164162 alignSelf : 'center' ,
165163 } ,
166164 defaultContainer : {
167- padding : 8 ,
168165 flexDirection : 'row' ,
166+ padding : 8 ,
169167 } ,
170168 defaultTextContainer : {
171169 flex : 1 ,
172- padding : 8 ,
170+ paddingHorizontal : 8 ,
173171 } ,
174172 translucent : false ,
175173 activeStatusBarStyle : 'light-content' ,
@@ -231,7 +229,7 @@ export default class DropdownAlert extends Component {
231229 this . _onDonePan ( event , gestureState ) ,
232230 } ) ;
233231 } ;
234- _onShouldStartPan = ( event , gestureState ) => {
232+ _onShouldStartPan = ( ) => {
235233 return this . props . panResponderEnabled ;
236234 } ;
237235 _onShouldMovePan = ( event , gestureState ) => {
@@ -254,7 +252,7 @@ export default class DropdownAlert extends Component {
254252 this . closeAction ( ACTION . pan ) ;
255253 }
256254 } ;
257- getStringValue ( value ) {
255+ getStringValue = ( value ) => {
258256 try {
259257 if ( typeof value !== 'string' ) {
260258 if ( Array . isArray ( value ) ) {
@@ -269,7 +267,7 @@ export default class DropdownAlert extends Component {
269267 } catch ( error ) {
270268 return error . toString ( ) ;
271269 }
272- }
270+ } ;
273271 alertWithType = async (
274272 type = '' ,
275273 title = '' ,
@@ -426,7 +424,7 @@ export default class DropdownAlert extends Component {
426424 const end = this . getEndDelta ( height , endDelta ) ;
427425 return [ start , end ] ;
428426 } ;
429- getStyleForType ( type ) {
427+ getStyleForType = ( type ) => {
430428 const { defaultContainer} = this . props ;
431429 switch ( type ) {
432430 case TYPE . info :
@@ -455,8 +453,8 @@ export default class DropdownAlert extends Component {
455453 StyleSheet . flatten ( this . props . containerStyle ) ,
456454 ] ;
457455 }
458- }
459- getSourceForType ( type ) {
456+ } ;
457+ getSourceForType = ( type ) => {
460458 switch ( type ) {
461459 case TYPE . info :
462460 return this . props . infoImageSrc ;
@@ -469,8 +467,8 @@ export default class DropdownAlert extends Component {
469467 default :
470468 return this . props . imageSrc ;
471469 }
472- }
473- getBackgroundColorForType ( type ) {
470+ } ;
471+ getBackgroundColorForType = ( type ) => {
474472 switch ( type ) {
475473 case TYPE . info :
476474 return this . props . infoColor ;
@@ -483,8 +481,8 @@ export default class DropdownAlert extends Component {
483481 default :
484482 return this . props . containerStyle . backgroundColor ;
485483 }
486- }
487- _onLayoutEvent ( event ) {
484+ } ;
485+ _onLayoutEvent = ( event ) => {
488486 const { height} = event . nativeEvent . layout ;
489487 if ( height > this . state . height ) {
490488 const { startDelta, endDelta} = this . props ;
@@ -494,63 +492,75 @@ export default class DropdownAlert extends Component {
494492 this . setState ( { height} ) ;
495493 }
496494 }
497- }
498- _renderImage ( source ) {
499- if ( this . props . renderImage ) {
500- return this . props . renderImage ( this . props , this . alertData ) ;
495+ } ;
496+ _renderImage = ( source , imageStyle ) => {
497+ const { renderImage} = this . props ;
498+ if ( renderImage ) {
499+ return renderImage ( this . props , this . alertData ) ;
501500 }
502- return (
503- < ImageView
504- style = { StyleSheet . flatten ( this . props . imageStyle ) }
505- source = { source }
506- />
507- ) ;
508- }
509- _renderTitle ( ) {
501+ if ( ! source ) {
502+ return null ;
503+ }
504+ let style = imageStyle ;
505+ if ( ! style . width ) {
506+ style . width = DEFAULT_IMAGE_DIMENSIONS ;
507+ }
508+ if ( ! style . height ) {
509+ style . height = DEFAULT_IMAGE_DIMENSIONS ;
510+ }
511+ const isRemote = typeof source === 'string' ;
512+ const src = isRemote ? { uri : source } : source ;
513+ return < Image style = { style } source = { src } /> ;
514+ } ;
515+ _renderTitle = ( ) => {
510516 if ( this . props . renderTitle ) {
511517 return this . props . renderTitle ( this . props , this . alertData ) ;
512518 }
513519 const { titleTextProps, titleStyle, titleNumOfLines} = this . props ;
514520 return (
515- < TextView
521+ < Text
516522 { ...titleTextProps }
517- style = { StyleSheet . flatten ( titleStyle ) }
518- numberOfLines = { titleNumOfLines }
519- text = { this . alertData . title }
520- / >
523+ style = { titleStyle }
524+ numberOfLines = { titleNumOfLines } >
525+ { this . alertData . title }
526+ </ Text >
521527 ) ;
522- }
523- _renderMessage ( ) {
528+ } ;
529+ _renderMessage = ( ) => {
524530 if ( this . props . renderMessage ) {
525531 return this . props . renderMessage ( this . props , this . alertData ) ;
526532 }
527533 const { messageTextProps, messageStyle, messageNumOfLines} = this . props ;
528534 return (
529- < TextView
535+ < Text
530536 { ...messageTextProps }
531- style = { StyleSheet . flatten ( messageStyle ) }
532- numberOfLines = { messageNumOfLines }
533- text = { this . alertData . message }
534- / >
537+ style = { messageStyle }
538+ numberOfLines = { messageNumOfLines } >
539+ { this . alertData . message }
540+ </ Text >
535541 ) ;
536- }
537- _renderCancel ( show = false ) {
542+ } ;
543+ _renderCancel = ( show = false ) => {
538544 if ( ! show ) {
539545 return null ;
540546 }
541- if ( this . props . renderCancel ) {
542- return this . props . renderCancel ( this . props , this . alertData ) ;
543- } else {
544- const { cancelBtnImageSrc, cancelBtnImageStyle} = this . props ;
545- return (
546- < CancelButton
547- imageStyle = { cancelBtnImageStyle }
548- imageSrc = { cancelBtnImageSrc }
549- onPress = { ( ) => this . closeAction ( ACTION . cancel ) }
550- />
551- ) ;
547+ const {
548+ renderCancel,
549+ cancelBtnStyle,
550+ cancelBtnImageSrc,
551+ cancelBtnImageStyle,
552+ } = this . props ;
553+ if ( renderCancel ) {
554+ return renderCancel ( this . props , this . alertData ) ;
552555 }
553- }
556+ return (
557+ < TouchableOpacity
558+ style = { cancelBtnStyle }
559+ onPress = { ( ) => this . closeAction ( ACTION . cancel ) } >
560+ { this . _renderImage ( cancelBtnImageSrc , cancelBtnImageStyle ) }
561+ </ TouchableOpacity >
562+ ) ;
563+ } ;
554564 render ( ) {
555565 const { isOpen} = this . state ;
556566 if ( ! isOpen ) {
@@ -571,6 +581,7 @@ export default class DropdownAlert extends Component {
571581 translucent,
572582 updateStatusBar,
573583 showCancel,
584+ imageStyle,
574585 } = this . props ;
575586 const { animationValue, topValue, height} = this . state ;
576587 const { type, payload} = this . alertData ;
@@ -632,7 +643,7 @@ export default class DropdownAlert extends Component {
632643 accessible = { accessible } >
633644 < View style = { style } >
634645 < ContentView style = { StyleSheet . flatten ( contentContainerStyle ) } >
635- { this . _renderImage ( imageSrc ) }
646+ { this . _renderImage ( imageSrc , imageStyle ) }
636647 < View style = { StyleSheet . flatten ( defaultTextContainer ) } >
637648 { this . _renderTitle ( ) }
638649 { this . _renderMessage ( ) }
0 commit comments