Skip to content

Commit faeed86

Browse files
Merge pull request #48 from testshallpass/status-bar-style-29-fix
Status bar style 29 fix
2 parents 1f0f5ad + 5837703 commit faeed86

File tree

12 files changed

+1280
-181
lines changed

12 files changed

+1280
-181
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ ISSUE_TEMPLATE.md
1010
.babelrc
1111
babelrc
1212
test/
13+
__tests__/

DropdownAlert.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
21
import React, { Component, PropTypes } from 'react'
3-
import {
4-
View, Text, StyleSheet,
5-
TouchableHighlight, Animated, StatusBar,
6-
Platform, Dimensions, Image, PanResponder
7-
} from "react-native"
8-
9-
// Constants
10-
// Sizes
2+
import {StyleSheet, View, Text, TouchableHighlight, Animated, StatusBar, Platform, Dimensions, Image, PanResponder} from "react-native"
3+
const StatusBarDefaultBarStyle = StatusBar._defaultProps.barStyle.value
4+
const StatusBarDefaultBackgroundColor = StatusBar._defaultProps.backgroundColor.value
115
const DEFAULT_IMAGE_DIMENSIONS = 36
126
const WINDOW = Dimensions.get('window')
13-
147
var closeTimeoutId = null
158
var panResponder
169

@@ -44,7 +37,11 @@ export default class DropdownAlert extends Component {
4437
tapToCloseEnabled: PropTypes.bool,
4538
panResponderEnabled: PropTypes.bool,
4639
replaceEnabled: PropTypes.bool,
47-
translucent: PropTypes.bool
40+
translucent: PropTypes.bool,
41+
activeStatusBarStyle: PropTypes.string,
42+
activeStatusBarBackgroundColor: PropTypes.string,
43+
inactiveStatusBarStyle: PropTypes.string,
44+
inactiveStatusBarBackgroundColor: PropTypes.string
4845
}
4946
static defaultProps = {
5047
onClose: null,
@@ -94,7 +91,11 @@ export default class DropdownAlert extends Component {
9491
height: DEFAULT_IMAGE_DIMENSIONS,
9592
alignSelf: 'center'
9693
},
97-
translucent: false
94+
translucent: false,
95+
activeStatusBarStyle: 'light-content',
96+
activeStatusBarBackgroundColor: StatusBarDefaultBackgroundColor,
97+
inactiveStatusBarStyle: StatusBarDefaultBarStyle,
98+
inactiveStatusBarBackgroundColor: StatusBarDefaultBackgroundColor
9899
}
99100
constructor(props) {
100101
super(props)
@@ -107,7 +108,7 @@ export default class DropdownAlert extends Component {
107108
isOpen: false,
108109
startDelta: props.startDelta,
109110
endDelta: props.endDelta,
110-
topValue: 0
111+
topValue: 0,
111112
}
112113
// Render
113114
this.renderButton = this.renderButton.bind(this)
@@ -212,6 +213,11 @@ export default class DropdownAlert extends Component {
212213
this.setState({
213214
isOpen: false
214215
})
216+
if (Platform.OS == 'android') {
217+
StatusBar.setBackgroundColor(this.props.inactiveStatusBarBackgroundColor, true)
218+
} else {
219+
StatusBar.setBarStyle(this.props.inactiveStatusBarStyle, true)
220+
}
215221
if (onDismiss) {
216222
var data = {
217223
type: this.state.type,
@@ -332,17 +338,13 @@ export default class DropdownAlert extends Component {
332338
}
333339
return null
334340
}
335-
renderStatusBar(type, backgroundColor) {
341+
renderStatusBar(backgroundColor, barStyle, translucent) {
336342
if (Platform.OS === 'android') {
337-
return (
338-
<StatusBar backgroundColor={backgroundColor} />
339-
)
340-
} else if (type != 'custom') {
341-
return (
342-
<StatusBar barStyle="light-content" />
343-
)
343+
StatusBar.setBackgroundColor(backgroundColor, true)
344+
StatusBar.setTranslucent(translucent)
345+
} else if (Platform.OS === 'ios') {
346+
StatusBar.setBarStyle(barStyle, true)
344347
}
345-
return null
346348
}
347349
renderButton(source, style, onPress, underlayColor, isRendered) {
348350
if (source != null && isRendered) {
@@ -381,11 +383,16 @@ export default class DropdownAlert extends Component {
381383
backgroundColor = this.props.successColor
382384
break;
383385
}
384-
385-
if (Platform.OS === 'android' && this.props.translucent) {
386-
style = [style, { paddingTop: StatusBar.currentHeight }]
386+
var activeStatusBarBackgroundColor = this.props.activeStatusBarBackgroundColor
387+
if (Platform.OS === 'android') {
388+
if (this.props.translucent) {
389+
style = [style, {paddingTop: StatusBar.currentHeight}]
390+
}
391+
if (this.state.type !== 'custom') {
392+
activeStatusBarBackgroundColor = backgroundColor
393+
}
387394
}
388-
395+
this.renderStatusBar(activeStatusBarBackgroundColor, this.props.activeStatusBarStyle, this.props.translucent)
389396
return (
390397
<Animated.View
391398
ref={(ref) => this.mainView = ref}
@@ -402,7 +409,6 @@ export default class DropdownAlert extends Component {
402409
left: 0,
403410
right: 0
404411
}}>
405-
{this.renderStatusBar(this.state.type, backgroundColor)}
406412
<TouchableHighlight
407413
onPress={(this.props.showCancel) ? null : () => this.onClose('tap')}
408414
underlayColor={backgroundColor}

0 commit comments

Comments
 (0)