Skip to content
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
48 changes: 28 additions & 20 deletions lib/items.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component, } from 'react';
const ReactNative = require('react-native');

import React, { Component } from "react";
const ReactNative = require("react-native");
import PropTypes from "prop-types";
const {
Dimensions,
StyleSheet,
Expand All @@ -10,40 +10,47 @@ const {
Text
} = ReactNative;

const window = Dimensions.get('window');
const window = Dimensions.get("window");

const styles = StyleSheet.create({
scrollView: {
height: 120,
width: 198 //TODO: this needs to be dynamic
},
container: {
position: 'absolute',
borderColor: '#BDBDC1',
position: "absolute",
borderColor: "#BDBDC1",
borderWidth: 2 / window.scale,
borderTopColor: 'transparent',
borderTopColor: "transparent"
}
})
});

class Items extends Component {
constructor(props) {
super(props);
}

render() {
const { items, positionX, positionY, show, onPress, width, height } = this.props;
const {
items,
positionX,
positionY,
show,
onPress,
width,
height
} = this.props;

if (!show) {
return null;
}

const renderedItems = React.Children.map(items, (item) => {

const renderedItems = React.Children.map(items, item => {
return (
<TouchableWithoutFeedback onPress={() => onPress(item.props.children, item.props.value) }>
<View>
{item}
</View>
<TouchableWithoutFeedback
onPress={() => onPress(item.props.children, item.props.value)}
>
<View>{item}</View>
</TouchableWithoutFeedback>
);
});
Expand All @@ -53,7 +60,8 @@ class Items extends Component {
<ScrollView
style={{ width: width - 2, height: height * 3 }}
automaticallyAdjustContentInsets={false}
bounces={false}>
bounces={false}
>
{renderedItems}
</ScrollView>
</View>
Expand All @@ -62,10 +70,10 @@ class Items extends Component {
}

Items.propTypes = {
positionX: React.PropTypes.number,
positionY: React.PropTypes.number,
show: React.PropTypes.bool,
onPress: React.PropTypes.func
positionX: PropTypes.number,
positionY: PropTypes.number,
show: PropTypes.bool,
onPress: PropTypes.func
};

Items.defaultProps = {
Expand Down
21 changes: 8 additions & 13 deletions lib/option.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import React, { Component, } from 'react';
const ReactNative = require('react-native');

const {
StyleSheet,
View,
Text
} = ReactNative;

import React, { Component } from "react";
const ReactNative = require("react-native");
import PropTypes from "prop-types";
const { StyleSheet, View, Text } = ReactNative;

const styles = StyleSheet.create({
container: {
padding: 10,
backgroundColor: 'white',
backgroundColor: "white"
}
});

Expand All @@ -24,15 +19,15 @@ class Option extends Component {
const { style, styleText } = this.props;

return (
<View style={[ styles.container, style ]}>
<Text style={ styleText }>{this.props.children}</Text>
<View style={[styles.container, style]}>
<Text style={styleText}>{this.props.children}</Text>
</View>
);
}
}

Option.propTypes = {
children: React.PropTypes.string.isRequired
children: PropTypes.string.isRequired
};

module.exports = Option;
37 changes: 14 additions & 23 deletions lib/optionList.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
const Overlay = require('./overlay');
const Items = require('./items');
const Overlay = require("./overlay");
const Items = require("./items");
import PropTypes from "prop-types";
import React, { Component } from "react";
const ReactNative = require("react-native");

import React, { Component, } from 'react';
const ReactNative = require('react-native');
const { StyleSheet, View, Text, Dimensions } = ReactNative;

const {
StyleSheet,
View,
Text,
Dimensions,
} = ReactNative;



const window = Dimensions.get('window');
const window = Dimensions.get("window");

class OptionList extends Component {
constructor(props) {
Expand All @@ -32,7 +25,7 @@ class OptionList extends Component {
positionY: 0,

items: [],
onSelect: () => { }
onSelect: () => {}
};
}

Expand Down Expand Up @@ -98,26 +91,24 @@ class OptionList extends Component {
pageX={pageX}
pageY={pageY}
show={show}
onPress={ this._onOverlayPress.bind(this) }/>
onPress={this._onOverlayPress.bind(this)}
/>
<Items
items={items}
positionX={positionX}
positionY={positionY}
width={width}
height={height}
show={show}
onPress={ this._onItemPress.bind(this) }/>
onPress={this._onItemPress.bind(this)}
/>
</View>
);
}
}

OptionList.propTypes = {

};

OptionList.defaultProps = {
OptionList.propTypes = {};

};
OptionList.defaultProps = {};

module.exports = OptionList;
24 changes: 12 additions & 12 deletions lib/overlay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component, } from 'react';
const ReactNative = require('react-native');

import React, { Component } from "react";
const ReactNative = require("react-native");
import PropTypes from "prop-types";
const {
Dimensions,
StyleSheet,
Expand All @@ -10,19 +10,19 @@ const {
Text
} = ReactNative;

const window = Dimensions.get('window');
const window = Dimensions.get("window");

const styles = StyleSheet.create({
container: {
position: 'absolute',
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0
},
overlay: {
position: 'absolute',
backgroundColor: 'transparent',
position: "absolute",
backgroundColor: "transparent",
width: window.width,
height: window.height
}
Expand All @@ -37,21 +37,21 @@ class Overlay extends Component {
const { pageX, pageY, show, onPress } = this.props;

if (!show) {
return null
return null;
}

return (
<TouchableWithoutFeedback style={styles.container} onPress={onPress}>
<View style={[styles.overlay, { top: -pageY, left: -pageX }]}/>
<View style={[styles.overlay, { top: -pageY, left: -pageX }]} />
</TouchableWithoutFeedback>
);
}
}

Overlay.propTypes = {
pageX: React.PropTypes.number,
pageY: React.PropTypes.number,
show: React.PropTypes.bool
pageX: PropTypes.number,
pageY: PropTypes.number,
show: PropTypes.bool
};

Overlay.defaultProps = {
Expand Down
63 changes: 40 additions & 23 deletions lib/select.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Option = require('./option');

import React, { Component, } from 'react';
const ReactNative = require('react-native');
const Option = require("./option");
import PropTypes from "prop-types";
import React, { Component } from "react";
const ReactNative = require("react-native");

const {
Dimensions,
Expand All @@ -12,13 +12,13 @@ const {
Text
} = ReactNative;

const window = Dimensions.get('window');
const window = Dimensions.get("window");

const SELECT = 'SELECT';
const SELECT = "SELECT";

const styles = StyleSheet.create({
container: {
borderColor: '#BDBDC1',
borderColor: "#BDBDC1",
borderWidth: 2 / window.scale
}
});
Expand All @@ -42,7 +42,7 @@ class Select extends Component {

this.state = {
value: defaultValue
}
};
}

reset() {
Expand All @@ -62,41 +62,58 @@ class Select extends Component {
return false;
}

optionListRef()._show(children, this.pageX, this.pageY, width, height, (item, value=item) => {
if (item) {
onSelect(value);
this.setState({
value: item
});
optionListRef()._show(
children,
this.pageX,
this.pageY,
width,
height,
(item, value = item) => {
if (item) {
onSelect(value);
this.setState({
value: item
});
}
}
});
);
}

render() {
const { width, height, children, defaultValue, style, styleOption, styleText } = this.props;
const {
width,
height,
children,
defaultValue,
style,
styleOption,
styleText
} = this.props;
const dimensions = { width, height };

return (
<TouchableWithoutFeedback onPress={this._onPress.bind(this)}>
<View ref={SELECT} style={[styles.container, style, dimensions ]}>
<Option style={ styleOption } styleText={ styleText }>{this.state.value}</Option>
<View ref={SELECT} style={[styles.container, style, dimensions]}>
<Option style={styleOption} styleText={styleText}>
{this.state.value}
</Option>
</View>
</TouchableWithoutFeedback>
);
}
}

Select.propTypes = {
width: React.PropTypes.number,
height: React.PropTypes.number,
optionListRef: React.PropTypes.func.isRequired,
onSelect: React.PropTypes.func
width: PropTypes.number,
height: PropTypes.number,
optionListRef: PropTypes.func.isRequired,
onSelect: PropTypes.func
};

Select.defaultProps = {
width: 200,
height: 40,
onSelect: () => { }
onSelect: () => {}
};

module.exports = Select;
8 changes: 3 additions & 5 deletions lib/updatePosition.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const ReactNative = require('react-native');
const ReactNative = require("react-native");

const {
NativeModules: {
UIManager
}
NativeModules: { UIManager }
} = ReactNative;

module.exports = function (ref, debug) {
module.exports = function(ref, debug) {
const handle = ReactNative.findNodeHandle(ref);
setTimeout(() => {
UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
Expand Down