@@ -6,14 +6,22 @@ import {
66 TouchableOpacity ,
77} from 'react-native' ;
88import RRCTopView from './RRCTopView' ;
9- const { width } = Dimensions . get ( 'window' )
9+ const { width, height } = Dimensions . get ( 'window' )
1010const borderRadius = 10 ;
1111const backgroundColor = 'rgba(0,0,0,0.1)' ;
1212const titleTextFontSize = 16 ;
1313const buttonTextFontSize = 16 ;
1414const contentTextFontSize = 14 ;
1515
16+ let AlertOptions = { }
17+
1618export default class OverlayAlert {
19+ static setAlertOptions ( options = { } ) {
20+ if ( options . alertBackgroundColor != undefined ) {
21+ AlertOptions . alertBackgroundColor = options . alertBackgroundColor ;
22+ }
23+ }
24+
1725 static alert ( title , content , buttons , Callback , options ) {
1826 title = title || '' ;
1927 content = content || '' ;
@@ -27,107 +35,110 @@ export default class OverlayAlert {
2735 buttons = [ { text : 'OK' , style : { color : '#fd521d' , fontWeight : 'bold' } } ]
2836 }
2937 let key ;
38+ const alertBackgroundColor = AlertOptions . alertBackgroundColor ? AlertOptions . alertBackgroundColor : 'rgba(0,0,0,0.3)'
3039 const overlayView = (
31- < View style = { { width : width * 0.7 , borderRadius, backgroundColor : '#fff' , overflow : 'hidden' } } >
32- {
33- title . length > 0 ?
34- < View style = { {
35- padding : content . length < 1 ? 20 : 10 ,
36- justifyContent : 'center' ,
37- alignItems : 'center' ,
38- borderTopLeftRadius : borderRadius ,
39- borderTopRightRadius : borderRadius
40- } } >
41- < Text style = { { fontSize : titleTextFontSize , fontWeight : 'bold' } } > { title } </ Text >
42- </ View >
43- :
44- < View style = { {
45- height : borderRadius + 5 ,
46- borderTopLeftRadius : borderRadius ,
47- borderTopRightRadius : borderRadius
48- } } />
49- }
50- {
51- content . length > 0 ?
52- < Text style = { [ {
53- fontSize : contentTextFontSize ,
54- padding : 20 ,
55- paddingTop : 5 ,
56- textAlign : 'center' ,
57- } , { ...options . contentTextStyle } ] } >
58- { content }
59- </ Text >
60- : null
61- }
62- < View style = { {
63- height : 1 ,
64- backgroundColor,
65- flex : 1
66- } } />
67- {
68- buttons . length < 3 ?
69- < View style = { {
70- height : 44 ,
71- flex : 1 ,
72- flexDirection : 'row' ,
73- alignItems : 'center' ,
74- backgroundColor,
75- borderBottomLeftRadius : borderRadius ,
76- borderBottomRightRadius : borderRadius
77- } } >
78- {
79- buttons . map ( ( item , index ) => {
80- return (
81- < TouchableOpacity activeOpacity = { 0.5 } key = { 'alert-button-' + index } style = { {
82- flex : 1 ,
83- height : 44 ,
84- marginLeft : index == 0 ? 0 : 1 ,
85- justifyContent : 'center' ,
86- alignItems : 'center' ,
87- backgroundColor : '#fff' ,
88- borderBottomLeftRadius : index == 0 ? borderRadius : 0 ,
89- borderBottomRightRadius : index == buttons . length - 1 ? borderRadius : 0
90- } } onPress = { ( ) => {
91- RRCTopView . remove ( key ) ;
92- Callback && Callback ( index ) ;
93- } } >
94- < Text style = { [ { fontSize : buttonTextFontSize } , { ...item . style } ] } > { item . text } </ Text >
95- </ TouchableOpacity >
96- )
97- } )
98- }
99- </ View >
100- :
101- < View style = { {
102- height : 45 * buttons . length - 1 ,
103- alignItems : 'center' ,
104- backgroundColor,
105- borderBottomLeftRadius : borderRadius ,
106- borderBottomRightRadius : borderRadius
107- } } >
108- {
109- buttons . map ( ( item , index ) => {
110- return (
111- < TouchableOpacity activeOpacity = { 0.5 } key = { 'alert-button-' + index } style = { {
112- height : 44 ,
113- width : width * 0.7 ,
114- marginTop : index == 0 ? 0 : 1 ,
115- justifyContent : 'center' ,
116- alignItems : 'center' ,
117- backgroundColor : '#fff' ,
118- borderBottomLeftRadius : index == buttons . length - 1 ? borderRadius : 0 ,
119- borderBottomRightRadius : index == buttons . length - 1 ? borderRadius : 0
120- } } onPress = { ( ) => {
121- RRCTopView . remove ( key ) ;
122- Callback && Callback ( index ) ;
123- } } >
124- < Text style = { [ { fontSize : buttonTextFontSize } , { ...item . style } ] } > { item . text } </ Text >
125- </ TouchableOpacity >
126- )
127- } )
128- }
129- </ View >
130- }
40+ < View style = { { width, height, backgroundColor : alertBackgroundColor , justifyContent : 'center' , alignItems : 'center' } } >
41+ < View style = { { width : width * 0.7 , borderRadius, backgroundColor : '#fff' , overflow : 'hidden' } } >
42+ {
43+ title . length > 0 ?
44+ < View style = { {
45+ padding : content . length < 1 ? 20 : 10 ,
46+ justifyContent : 'center' ,
47+ alignItems : 'center' ,
48+ borderTopLeftRadius : borderRadius ,
49+ borderTopRightRadius : borderRadius
50+ } } >
51+ < Text style = { { fontSize : titleTextFontSize , fontWeight : 'bold' } } > { title } </ Text >
52+ </ View >
53+ :
54+ < View style = { {
55+ height : borderRadius + 5 ,
56+ borderTopLeftRadius : borderRadius ,
57+ borderTopRightRadius : borderRadius
58+ } } />
59+ }
60+ {
61+ content . length > 0 ?
62+ < Text style = { [ {
63+ fontSize : contentTextFontSize ,
64+ padding : 20 ,
65+ paddingTop : 5 ,
66+ textAlign : 'center' ,
67+ } , { ...options . contentTextStyle } ] } >
68+ { content }
69+ </ Text >
70+ : null
71+ }
72+ < View style = { {
73+ height : 1 ,
74+ backgroundColor,
75+ width : width * 0.7
76+ } } />
77+ {
78+ buttons . length < 3 ?
79+ < View style = { {
80+ height : 44 ,
81+ // flex: 1,
82+ flexDirection : 'row' ,
83+ alignItems : 'center' ,
84+ backgroundColor,
85+ borderBottomLeftRadius : borderRadius ,
86+ borderBottomRightRadius : borderRadius
87+ } } >
88+ {
89+ buttons . map ( ( item , index ) => {
90+ return (
91+ < TouchableOpacity activeOpacity = { 0.5 } key = { 'alert-button-' + index } style = { {
92+ flex : 1 ,
93+ height : 44 ,
94+ marginLeft : index == 0 ? 0 : 1 ,
95+ justifyContent : 'center' ,
96+ alignItems : 'center' ,
97+ backgroundColor : '#fff' ,
98+ borderBottomLeftRadius : index == 0 ? borderRadius : 0 ,
99+ borderBottomRightRadius : index == buttons . length - 1 ? borderRadius : 0
100+ } } onPress = { ( ) => {
101+ RRCTopView . remove ( key ) ;
102+ Callback && Callback ( index ) ;
103+ } } >
104+ < Text style = { [ { fontSize : buttonTextFontSize } , { ...item . style } ] } > { item . text } </ Text >
105+ </ TouchableOpacity >
106+ )
107+ } )
108+ }
109+ </ View >
110+ :
111+ < View style = { {
112+ height : 45 * buttons . length - 1 ,
113+ alignItems : 'center' ,
114+ backgroundColor,
115+ borderBottomLeftRadius : borderRadius ,
116+ borderBottomRightRadius : borderRadius
117+ } } >
118+ {
119+ buttons . map ( ( item , index ) => {
120+ return (
121+ < TouchableOpacity activeOpacity = { 0.5 } key = { 'alert-button-' + index } style = { {
122+ height : 44 ,
123+ width : width * 0.7 ,
124+ marginTop : index == 0 ? 0 : 1 ,
125+ justifyContent : 'center' ,
126+ alignItems : 'center' ,
127+ backgroundColor : '#fff' ,
128+ borderBottomLeftRadius : index == buttons . length - 1 ? borderRadius : 0 ,
129+ borderBottomRightRadius : index == buttons . length - 1 ? borderRadius : 0
130+ } } onPress = { ( ) => {
131+ RRCTopView . remove ( key ) ;
132+ Callback && Callback ( index ) ;
133+ } } >
134+ < Text style = { [ { fontSize : buttonTextFontSize } , { ...item . style } ] } > { item . text } </ Text >
135+ </ TouchableOpacity >
136+ )
137+ } )
138+ }
139+ </ View >
140+ }
141+ </ View >
131142 </ View >
132143 )
133144 let onDisappearCompletedSave = overlayView . props . onDisappearCompleted ;
0 commit comments