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

Support latest react native version #259

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
86 changes: 45 additions & 41 deletions components/ModalDropdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Created by sohobloo on 16/9/13.
* Updated by TheFabiCraft
*/

'use strict';
Expand All @@ -9,6 +10,7 @@ import React, {
} from 'react';

import {
FlatList,
StyleSheet,
Dimensions,
View,
Expand All @@ -21,7 +23,7 @@ import {
ActivityIndicator,
} from 'react-native';

import ListView from "deprecated-react-native-listview";
// import ListView from "deprecated-react-native-listview";
import PropTypes from 'prop-types';

const TOUCHABLE_ELEMENTS = [
Expand Down Expand Up @@ -88,7 +90,7 @@ export default class ModalDropdown extends Component {
};
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
let {buttonText, selectedIndex} = this.state;
const {defaultIndex, defaultValue, options} = nextProps;
buttonText = this._nextValue == null ? buttonText : this._nextValue;
Expand All @@ -109,7 +111,7 @@ export default class ModalDropdown extends Component {
});
}

render() {
render () {
return (
<View {...this.props}>
{this._renderButton()}
Expand Down Expand Up @@ -168,16 +170,16 @@ export default class ModalDropdown extends Component {

return (
<TouchableOpacity ref={button => this._button = button}
disabled={disabled}
accessible={accessible}
onPress={this._onButtonPress}
disabled={disabled}
accessible={accessible}
onPress={this._onButtonPress}
>
{
children ||
(
<View style={styles.button}>
<Text style={[styles.buttonText, textStyle]}
numberOfLines={1}
numberOfLines={1}
>
{buttonText}
</Text>
Expand All @@ -203,15 +205,16 @@ export default class ModalDropdown extends Component {
const frameStyle = this._calcPosition();
const animationType = animated ? 'fade' : 'none';
return (
<Modal animationType={animationType}
visible={true}
transparent={true}
onRequestClose={this._onRequestClose}
supportedOrientations={['portrait', 'portrait-upside-down', 'landscape', 'landscape-left', 'landscape-right']}
<Modal
animationType={animationType}
visible
transparent
onRequestClose={this._onRequestClose}
supportedOrientations={['portrait', 'portrait-upside-down', 'landscape', 'landscape-left', 'landscape-right']}
>
<TouchableWithoutFeedback accessible={accessible}
disabled={!showDropdown}
onPress={this._onModalPress}
disabled={!showDropdown}
onPress={this._onModalPress}
>
<View style={styles.modal}>
<View style={[styles.dropdown, dropdownStyle, frameStyle]}>
Expand Down Expand Up @@ -281,29 +284,35 @@ export default class ModalDropdown extends Component {
}

_renderDropdown() {
const {scrollEnabled, renderSeparator, showsVerticalScrollIndicator, keyboardShouldPersistTaps} = this.props;
const {scrollEnabled, showsVerticalScrollIndicator, keyboardShouldPersistTaps, options} = this.props;
const Separator = <View style={styles.separator} />
return (
<ListView scrollEnabled={scrollEnabled}
style={styles.list}
dataSource={this._dataSource}
renderRow={this._renderRow}
renderSeparator={renderSeparator || this._renderSeparator}
automaticallyAdjustContentInsets={false}
showsVerticalScrollIndicator={showsVerticalScrollIndicator}
keyboardShouldPersistTaps={keyboardShouldPersistTaps}
<FlatList
scrollEnabled={scrollEnabled}
style={styles.list}
// dataSource={this._dataSource}
ItemSeparatorComponent={this._renderSeparator}
data={options}
keyExtractor={this._keyExtractor}
renderItem={this._renderRow}
automaticallyAdjustContentInsets={false}
showsVerticalScrollIndicator={showsVerticalScrollIndicator}
keyboardShouldPersistTaps={keyboardShouldPersistTaps}
/>
);
}

get _dataSource() {
const {options} = this.props;
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
});
return ds.cloneWithRows(options);
}
_keyExtractor = (item, index) => `${index}`

// get _dataSource() {
// const {options} = this.props;
// const ds = new ListView.DataSource({
// rowHasChanged: (r1, r2) => r1 !== r2
// });
// return ds.cloneWithRows(options);
// }

_renderRow = (rowData, sectionID, rowID, highlightRow) => {
_renderRow = ({item: rowData, index: rowID, separators}) => {
const {renderRow, dropdownTextStyle, dropdownTextHighlightStyle, accessible} = this.props;
const {selectedIndex} = this.state;
const key = `row_${rowID}`;
Expand All @@ -322,7 +331,7 @@ export default class ModalDropdown extends Component {
const preservedProps = {
key,
accessible,
onPress: () => this._onRowPress(rowData, sectionID, rowID, highlightRow),
onPress: () => this._onRowPress(rowData, rowID),
};
if (TOUCHABLE_ELEMENTS.find(name => name == row.type.displayName)) {
const props = {...row.props};
Expand Down Expand Up @@ -369,10 +378,10 @@ export default class ModalDropdown extends Component {
);
};

_onRowPress(rowData, sectionID, rowID, highlightRow) {
_onRowPress(rowData, rowID) {
const {onSelect, renderButtonText, onDropdownWillHide} = this.props;
if (!onSelect || onSelect(rowID, rowData) !== false) {
highlightRow(sectionID, rowID);
// highlightRow(sectionID, rowID);
const value = renderButtonText && renderButtonText(rowData) || rowData.toString();
this._nextValue = value;
this._nextIndex = rowID;
Expand All @@ -388,13 +397,8 @@ export default class ModalDropdown extends Component {
}
}

_renderSeparator = (sectionID, rowID, adjacentRowHighlighted) => {
const key = `spr_${rowID}`;
return (
<View style={styles.separator}
key={key}
/>
);
_renderSeparator = () => {
return <View style={styles.separator} />
};
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-modal-dropdown",
"version": "0.7.0",
"version": "0.7.1",
"description": "A react-native dropdown component for both iOS and Android.",
"keywords": [
"react",
Expand Down