Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add POSITION enum to ToastContainer #2781

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/basic/ToastContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import { Platform, Animated, ViewPropTypes } from 'react-native';
import { connectStyle } from 'native-base-shoutem-theme';

import mapPropsToStyleNames from '../utils/mapPropsToStyleNames';
import { PLATFORM } from '../theme/variables/commonColor';

import { Text } from './Text';
import { Button } from './Button';
import { Toast } from './Toast';

const POSITION = {
ABSOLUTE: 'absolute',
BOTTOM: 'bottom',
TOP: 'top'
};

class ToastContainer extends Component {

static toastInstance;
static show({ ...config }) {
this.toastInstance._root.showToast({ config });
Expand All @@ -31,27 +36,28 @@ class ToastContainer extends Component {
}
getToastStyle() {
return {
position: 'absolute',
position: POSITION.ABSOLUTE,
opacity: this.state.fadeAnim,
width: '100%',
elevation: 9,
paddingHorizontal: Platform.OS === 'ios' ? 20 : 0,
top: this.state.position === 'top' ? this.getTop() : undefined,
bottom: this.state.position === 'bottom' ? this.getTop() : undefined
paddingHorizontal: Platform.OS === PLATFORM.IOS ? 20 : 0,
top: this.state.position === POSITION.TOP ? this.getTop() : undefined,
bottom:
this.state.position === POSITION.BOTTOM ? this.getTop() : undefined
};
}
getTop() {
if (Platform.OS === 'ios') {
if (Platform.OS === PLATFORM.IOS) {
return 30;
}
}
return 0;

}
getButtonText(buttonText) {
if (buttonText) {
if (buttonText.trim().length === 0) {
return undefined;
} return buttonText;
}
return buttonText;
}
return undefined;
}
Expand All @@ -64,7 +70,7 @@ class ToastContainer extends Component {
text: config.text,
buttonText: this.getButtonText(config.buttonText),
type: config.type,
position: config.position ? config.position : 'bottom',
position: config.position ? config.position : POSITION.BOTTOM,
supportedOrientations: config.supportedOrientations,
style: config.style,
buttonTextStyle: config.buttonTextStyle,
Expand Down Expand Up @@ -106,6 +112,7 @@ class ToastContainer extends Component {
duration: 200
}).start(this.closeModal.bind(this, reason));
}

render() {
if (this.state.modalVisible) {
return (
Expand All @@ -130,7 +137,8 @@ class ToastContainer extends Component {
</Toast>
</Animated.View>
);
} return null;
}
return null;
}
}

Expand Down