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

Alignment #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion lib/Toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import {
View
} from 'react-native';
import RootSiblings from 'react-native-root-siblings';
import ToastContainer, {positions, durations} from './ToastContainer';
import ToastContainer, {positions, durations, alignments} from './ToastContainer';

class Toast extends Component {
static displayName = 'Toast';
static propTypes = ToastContainer.propTypes;
static positions = positions;
static durations = durations;
static alignments = alignments;

static show = (message, options = {position: positions.BOTTOM, duration: durations.SHORT}) => {
return new RootSiblings(<ToastContainer
Expand Down
25 changes: 19 additions & 6 deletions lib/ToastContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ const positions = {
BOTTOM: -20,
CENTER: 0
};

const durations = {
LONG: 3500,
SHORT: 2000
};
const alignments = {
LEFT: 'flex-start',
CENTER: 'center',
RIGHT: 'flex-end',
}

let styles = StyleSheet.create({
defaultStyle: {
Expand All @@ -39,7 +43,8 @@ let styles = StyleSheet.create({
padding: 10,
backgroundColor: '#000',
opacity: 0.8,
borderRadius: 5
borderRadius: 5,
marginHorizontal: 10,
},
shadowStyle: {
shadowColor: '#000',
Expand Down Expand Up @@ -79,7 +84,8 @@ class ToastContainer extends Component {
onHide: PropTypes.func,
onHidden: PropTypes.func,
onShow: PropTypes.func,
onShown: PropTypes.func
onShown: PropTypes.func,
alignment: PropTypes.oneOf([alignments.LEFT, alignments.CENTER, alignments.RIGHT]),
};

static defaultProps = {
Expand All @@ -90,7 +96,8 @@ class ToastContainer extends Component {
position: positions.BOTTOM,
opacity: 0.8,
delay: 0,
hideOnPress: true
hideOnPress: true,
alignment: alignments.CENTER,
};

constructor() {
Expand Down Expand Up @@ -212,17 +219,22 @@ class ToastContainer extends Component {
let {props} = this;
const { windowWidth } = this.state;
let offset = props.position;
const { alignment } = props;
let position = offset ? {
[offset < 0 ? 'bottom' : 'top']: offset < 0 ? (this._keyboardHeight - offset) : offset
} : {
top: 0,
bottom: this._keyboardHeight
};
const alignItems = {
alignItems: alignment,
}

return (this.state.visible || this._animating) ? <View
style={[
styles.defaultStyle,
position
position,
alignItems,
]}
pointerEvents="box-none"
>
Expand Down Expand Up @@ -260,5 +272,6 @@ class ToastContainer extends Component {
export default ToastContainer;
export {
positions,
durations
durations,
alignments
}