Skip to content

Commit 91c6ef3

Browse files
committed
support Toast component safe area
1 parent 7f94282 commit 91c6ef3

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

demo/src/screens/componentScreens/ToastsScreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class AvatarsScreen extends Component {
1010

1111
render() {
1212
return (
13-
<View flex useSafeArea>
13+
<View flex>
1414
<Carousel onChangePage={currentPage => this.setState({currentPage})} initialPage={this.state.currentPage}>
1515
<View style={styles.page} bg-red50>
1616
<Toast visible message="Discount was added to 3 products" />

src/components/toast/index.js

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ export default class Toast extends BaseComponent {
118118
setupRelativeAnimation(getHeight(nextProps));
119119
}
120120

121-
const newState = animated ? {
122-
animationConfig: this.getAnimation(visible),
123-
contentAnimation: this.getContentAnimation(visible),
124-
} : {
125-
animationConfig: {},
126-
contentAnimation: {},
127-
};
121+
const newState = animated
122+
? {
123+
animationConfig: this.getAnimation(visible),
124+
contentAnimation: this.getContentAnimation(visible),
125+
}
126+
: {
127+
animationConfig: {},
128+
contentAnimation: {},
129+
};
128130

129131
this.setState(newState);
130132
}
@@ -137,7 +139,7 @@ export default class Toast extends BaseComponent {
137139
getPositionStyle() {
138140
const {position} = this.props;
139141

140-
return (position === 'relative') ? {position} : getAbsolutePositionStyle(position);
142+
return position === 'relative' ? {position} : getAbsolutePositionStyle(position);
141143
}
142144

143145
getAnimation(shouldShow) {
@@ -225,6 +227,7 @@ export default class Toast extends BaseComponent {
225227
}
226228
}
227229

230+
// This weird layout should support iphoneX safe are
228231
render() {
229232
const {backgroundColor, actions, allowDismiss, enableBlur, zIndex} = this.getThemeProps();
230233
const {animationConfig} = this.state;
@@ -240,29 +243,33 @@ export default class Toast extends BaseComponent {
240243
}
241244

242245
return (
243-
<Animatable.View
244-
style={[
245-
this.styles.container,
246-
hasOneAction && this.styles.containerWithOneAction,
247-
positionStyle,
248-
backgroundColor && {backgroundColor},
249-
{height},
250-
{zIndex},
251-
]}
252-
{...animationConfig}
253-
>
254-
{enableBlur && <BlurView style={this.styles.blurView} {...blurOptions} />}
255-
<View row flex centerV spread>
256-
{this.renderMessage()}
257-
{(hasOneAction || allowDismiss) && (
258-
<View row height="100%">
259-
{hasOneAction && this.renderOneAction()}
260-
{this.renderDismissButton()}
261-
</View>
262-
)}
263-
</View>
264-
{hasTwoActions && <View>{this.renderTwoActions()}</View>}
265-
</Animatable.View>
246+
<View style={[positionStyle]} useSafeArea>
247+
<View height={height} />
248+
249+
<Animatable.View
250+
style={[
251+
this.styles.container,
252+
backgroundColor && {backgroundColor},
253+
hasOneAction && this.styles.containerWithOneAction,
254+
{zIndex},
255+
]}
256+
{...animationConfig}
257+
>
258+
{enableBlur && <BlurView style={this.styles.blurView} {...blurOptions} />}
259+
260+
<View row height={height} centerV spread>
261+
{this.renderMessage()}
262+
{(hasOneAction || allowDismiss) && (
263+
<View row height="100%">
264+
{hasOneAction && this.renderOneAction()}
265+
{this.renderDismissButton()}
266+
</View>
267+
)}
268+
</View>
269+
270+
{hasTwoActions && <View>{this.renderTwoActions()}</View>}
271+
</Animatable.View>
272+
</View>
266273
);
267274
}
268275

@@ -283,6 +290,7 @@ export default class Toast extends BaseComponent {
283290
function createStyles() {
284291
return StyleSheet.create({
285292
container: {
293+
...StyleSheet.absoluteFillObject,
286294
backgroundColor: Colors.rgba(ThemeManager.primaryColor, 0.8),
287295
paddingHorizontal: 15,
288296
},
@@ -360,7 +368,7 @@ function setupRelativeAnimation(height) {
360368

361369
function getHeight({height, actions}) {
362370
if (_.isUndefined(height)) {
363-
return (_.size(actions) === 2) ? 92 : 48;
371+
return _.size(actions) === 2 ? 92 : 48;
364372
}
365373
return height;
366374
}

0 commit comments

Comments
 (0)