1.4.0 • Published 6 years ago

react-native-multi-state-modal v1.4.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

react-native-multi-state-modal

npm version

A simple and customisable react-native multi-state modal

Features

  • Customizable state by array of height
  • Customizable speed during transition
  • Draggable

Demo

Setup

Install it with:

npm install --save react-native-multi-state-modal , or

yarn add react-native-multi-state-modal.

Usage

import React, {Component} from 'react';
import {Dimensions, StyleSheet, Text, View, TouchableOpacity} from 'react-native';
import Modal from 'react-native-multi-state-modal'

const { width, height } = Dimensions.get('window');

type Props = {};
export default class App extends Component<Props> {
  constructor(props) {
		super(props);

		this.state = {
			stateIndex: 0,
			buttonText: 'Open modal'
		}
	}

	render() {

		let { stateIndex } = this.state;
		return (
			<View style={styles.container}>
				<View style={{flex: 1}} >
					<TouchableOpacity 
						style={styles.button}
						onPress={() => this.setState({stateIndex: stateIndex == 0? 1 : 0})}>
						<Text style={{color: 'white', fontSize: 20}}>{this.state.buttonText}</Text>
					</TouchableOpacity>
				</View>
				<Modal
					style={{backgroundColor: 'white'}}
					states={[0, height * 3 / 16, height * 447 / 640 ]}
					stateIndex={stateIndex}
					speed={300} 
					onIndexChange={(index) => this.setState({stateIndex: index})} >
					<View style={{flex: 1}}>
						<Text style={{color: 'black', fontSize: 20}}>Test content</Text>
					</View>
				</Modal>
			</View>
		);
	}
}

const styles = StyleSheet.create({
	container: {
		flex: 1,
		justifyContent: 'center',
		alignItems: 'center',
		backgroundColor: '#F5FCFF',
	},
	button: {
		paddingHorizontal: 12, 
		paddingVertical: 6, 
		backgroundColor: 'grey'
	}
});

For a more complex example take a look at the /example directory.

props

NameTypeDefaultRequiredDescription
statesarrayNAYesArray oh height of each state in ascending order
stateIndexnumberNAYesState index
enableDragbooleantrueNoset it to true to enable drag
speednumber300NoSpeed during transition between states
onPressfuncnullNoif onPress is not null and enableDrag is false, this function will be triggered
onIndexChangefuncnullNofunction that gives you the index after change
1.4.0

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago