Skip to content

Commit

Permalink
Merge pull request #852 from vjeux/import_everycommit
Browse files Browse the repository at this point in the history
Import everycommit
  • Loading branch information
vjeux committed Apr 15, 2015
2 parents bac60f5 + 970dd8a commit 862d9fb
Show file tree
Hide file tree
Showing 75 changed files with 2,016 additions and 1,310 deletions.
27 changes: 27 additions & 0 deletions Examples/SampleApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# node.js
#
node_modules/
npm-debug.log
82 changes: 64 additions & 18 deletions Examples/UIExplorer/MapViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,44 @@ var {
View,
} = React;

var regionText = {
latitude: '0',
longitude: '0',
latitudeDelta: '0',
longitudeDelta: '0',
}

var MapRegionInput = React.createClass({

propTypes: {
region: React.PropTypes.shape({
latitude: React.PropTypes.number,
longitude: React.PropTypes.number,
latitudeDelta: React.PropTypes.number,
longitudeDelta: React.PropTypes.number,
latitude: React.PropTypes.number.isRequired,
longitude: React.PropTypes.number.isRequired,
latitudeDelta: React.PropTypes.number.isRequired,
longitudeDelta: React.PropTypes.number.isRequired,
}),
onChange: React.PropTypes.func.isRequired,
},

getInitialState: function() {
return {
latitude: 0,
longitude: 0,
latitudeDelta: 0,
longitudeDelta: 0,
region: {
latitude: 0,
longitude: 0,
latitudeDelta: 0,
longitudeDelta: 0,
}
};
},

componentWillReceiveProps: function(nextProps) {
this.setState(nextProps.region);
this.setState({
region: nextProps.region || this.getInitialState().region
});
},

render: function() {
var region = this.state;
var region = this.state.region || this.getInitialState().region;
return (
<View>
<View style={styles.row}>
Expand All @@ -61,6 +72,7 @@ var MapRegionInput = React.createClass({
value={'' + region.latitude}
style={styles.textInput}
onChange={this._onChangeLatitude}
selectTextOnFocus={true}
/>
</View>
<View style={styles.row}>
Expand All @@ -71,6 +83,7 @@ var MapRegionInput = React.createClass({
value={'' + region.longitude}
style={styles.textInput}
onChange={this._onChangeLongitude}
selectTextOnFocus={true}
/>
</View>
<View style={styles.row}>
Expand All @@ -81,6 +94,7 @@ var MapRegionInput = React.createClass({
value={'' + region.latitudeDelta}
style={styles.textInput}
onChange={this._onChangeLatitudeDelta}
selectTextOnFocus={true}
/>
</View>
<View style={styles.row}>
Expand All @@ -91,6 +105,7 @@ var MapRegionInput = React.createClass({
value={'' + region.longitudeDelta}
style={styles.textInput}
onChange={this._onChangeLongitudeDelta}
selectTextOnFocus={true}
/>
</View>
<View style={styles.changeButton}>
Expand All @@ -103,23 +118,29 @@ var MapRegionInput = React.createClass({
},

_onChangeLatitude: function(e) {
this.setState({latitude: parseFloat(e.nativeEvent.text)});
regionText.latitude = e.nativeEvent.text;
},

_onChangeLongitude: function(e) {
this.setState({longitude: parseFloat(e.nativeEvent.text)});
regionText.longitude = e.nativeEvent.text;
},

_onChangeLatitudeDelta: function(e) {
this.setState({latitudeDelta: parseFloat(e.nativeEvent.text)});
regionText.latitudeDelta = e.nativeEvent.text;
},

_onChangeLongitudeDelta: function(e) {
this.setState({longitudeDelta: parseFloat(e.nativeEvent.text)});
regionText.longitudeDelta = e.nativeEvent.text;
},

_change: function() {
this.props.onChange(this.state);
this.setState({
latitude: parseFloat(regionText.latitude),
longitude: parseFloat(regionText.longitude),
latitudeDelta: parseFloat(regionText.latitudeDelta),
longitudeDelta: parseFloat(regionText.longitudeDelta),
});
this.props.onChange(this.state.region);
},

});
Expand All @@ -130,6 +151,8 @@ var MapViewExample = React.createClass({
return {
mapRegion: null,
mapRegionInput: null,
annotations: null,
isFirstLoad: true,
};
},

Expand All @@ -138,8 +161,10 @@ var MapViewExample = React.createClass({
<View>
<MapView
style={styles.map}
onRegionChange={this._onRegionChanged}
onRegionChange={this._onRegionChange}
onRegionChangeComplete={this._onRegionChangeComplete}
region={this.state.mapRegion}
annotations={this.state.annotations}
/>
<MapRegionInput
onChange={this._onRegionInputChanged}
Expand All @@ -149,14 +174,35 @@ var MapViewExample = React.createClass({
);
},

_onRegionChanged(region) {
this.setState({mapRegionInput: region});
_getAnnotations(region) {
return [{
longitude: region.longitude,
latitude: region.latitude,
title: 'You Are Here',
}];
},

_onRegionChange(region) {
this.setState({
mapRegionInput: region,
});
},

_onRegionChangeComplete(region) {
if (this.state.isFirstLoad) {
this.setState({
mapRegionInput: region,
annotations: this._getAnnotations(region),
isFirstLoad: false,
});
}
},

_onRegionInputChanged(region) {
this.setState({
mapRegion: region,
mapRegionInput: region,
annotations: this._getAnnotations(region),
});
},

Expand Down
136 changes: 136 additions & 0 deletions Examples/UIExplorer/PanResponderExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* @flow
*/
'use strict';

var React = require('react-native');
var {
StyleSheet,
PanResponder,
View,
} = React;

var CIRCLE_SIZE = 80;
var CIRCLE_COLOR = 'blue';
var CIRCLE_HIGHLIGHT_COLOR = 'green';


var NavigatorIOSExample = React.createClass({

statics: {
title: 'PanResponder Sample',
description: 'Basic gesture handling example',
},

_panResponder: {},
_previousLeft: 0,
_previousTop: 0,
_circleStyles: {},
circle: (null : ?{ setNativeProps(props: Object): void }),

componentWillMount: function() {
this._panResponder = PanResponder.create({
onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder,
onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,
onPanResponderGrant: this._handlePanResponderGrant,
onPanResponderMove: this._handlePanResponderMove,
onPanResponderRelease: this._handlePanResponderEnd,
onPanResponderTerminate: this._handlePanResponderEnd,
});
this._previousLeft = 20;
this._previousTop = 84;
this._circleStyles = {
left: this._previousLeft,
top: this._previousTop,
};
},

componentDidMount: function() {
this._updatePosition();
},

render: function() {
return (
<View
style={styles.container}>
<View
ref={(circle) => {
this.circle = circle;
}}
style={styles.circle}
{...this._panResponder.panHandlers}
/>
</View>
);
},

_highlight: function() {
this.circle && this.circle.setNativeProps({
backgroundColor: CIRCLE_HIGHLIGHT_COLOR
});
},

_unHighlight: function() {
this.circle && this.circle.setNativeProps({
backgroundColor: CIRCLE_COLOR
});
},

_updatePosition: function() {
this.circle && this.circle.setNativeProps(this._circleStyles);
},

_handleStartShouldSetPanResponder: function(e: Object, gestureState: Object): boolean {
// Should we become active when the user presses down on the circle?
return true;
},

_handleMoveShouldSetPanResponder: function(e: Object, gestureState: Object): boolean {
// Should we become active when the user moves a touch over the circle?
return true;
},

_handlePanResponderGrant: function(e: Object, gestureState: Object) {
this._highlight();
},
_handlePanResponderMove: function(e: Object, gestureState: Object) {
this._circleStyles.left = this._previousLeft + gestureState.dx;
this._circleStyles.top = this._previousTop + gestureState.dy;
this._updatePosition();
},
_handlePanResponderEnd: function(e: Object, gestureState: Object) {
this._unHighlight();
this._previousLeft += gestureState.dx;
this._previousTop += gestureState.dy;
},
});

var styles = StyleSheet.create({
circle: {
width: CIRCLE_SIZE,
height: CIRCLE_SIZE,
borderRadius: CIRCLE_SIZE / 2,
backgroundColor: CIRCLE_COLOR,
position: 'absolute',
left: 0,
top: 0,
},
container: {
flex: 1,
paddingTop: 64,
},
});

module.exports = NavigatorIOSExample;
27 changes: 26 additions & 1 deletion Examples/UIExplorer/TextInputExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var styles = StyleSheet.create({
flex: 1,
},
label: {
width: 80,
width: 120,
justifyContent: 'flex-end',
flexDirection: 'row',
marginRight: 10,
Expand Down Expand Up @@ -311,4 +311,29 @@ exports.examples = [
);
}
},
{
title: 'Clear and select',
render: function () {
return (
<View>
<WithLabel label="clearTextOnFocus">
<TextInput
placeholder="text is cleared on focus"
value="text is cleared on focus"
style={styles.default}
clearTextOnFocus={true}
/>
</WithLabel>
<WithLabel label="selectTextOnFocus">
<TextInput
placeholder="text is selected on focus"
value="text is selected on focus"
style={styles.default}
selectTextOnFocus={true}
/>
</WithLabel>
</View>
);
}
},
];
Loading

0 comments on commit 862d9fb

Please sign in to comment.