Skip to content

Commit

Permalink
Merge pull request #148 from vjeux/update1
Browse files Browse the repository at this point in the history
Updates from Fri 13 Mar
  • Loading branch information
frantic committed Mar 13, 2015
2 parents 252c9eb + 28aa691 commit c08243d
Show file tree
Hide file tree
Showing 26 changed files with 829 additions and 81 deletions.
34 changes: 18 additions & 16 deletions Examples/Movies/SearchScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ var SearchScreen = React.createClass({

fetch(this._urlForQueryAndPage(query, 1))
.then((response) => response.json())
.catch((error) => {
LOADING[query] = false;
resultsCache.dataForQuery[query] = undefined;

this.setState({
dataSource: this.getDataSource([]),
isLoading: false,
});
})
.then((responseData) => {
LOADING[query] = false;
resultsCache.totalForQuery[query] = responseData.total;
Expand All @@ -115,15 +124,7 @@ var SearchScreen = React.createClass({
dataSource: this.getDataSource(responseData.movies),
});
})
.catch((error) => {
LOADING[query] = false;
resultsCache.dataForQuery[query] = undefined;

this.setState({
dataSource: this.getDataSource([]),
isLoading: false,
});
});
.done();
},

hasMore: function(): boolean {
Expand Down Expand Up @@ -157,6 +158,13 @@ var SearchScreen = React.createClass({
var page = resultsCache.nextPageNumberForQuery[query];
fetch(this._urlForQueryAndPage(query, page))
.then((response) => response.json())
.catch((error) => {
console.error(error);
LOADING[query] = false;
this.setState({
isLoadingTail: false,
});
})
.then((responseData) => {
var moviesForQuery = resultsCache.dataForQuery[query].slice();

Expand All @@ -182,13 +190,7 @@ var SearchScreen = React.createClass({
dataSource: this.getDataSource(resultsCache.dataForQuery[query]),
});
})
.catch((error) => {
console.error(error);
LOADING[query] = false;
this.setState({
isLoadingTail: false,
});
});
.done();
},

getDataSource: function(movies: Array<any>): ListView.DataSource {
Expand Down
112 changes: 112 additions & 0 deletions Examples/UIExplorer/ActionSheetIOSExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* * Copyright 2004-present Facebook. All Rights Reserved.
* */
'use strict';

var React = require('react-native');
var {
StyleSheet,
Text,
View,
} = React;
var ActionSheetIOS = require('ActionSheetIOS');
var BUTTONS = [
'Button Index: 0',
'Button Index: 1',
'Button Index: 2',
'Destruct',
'Cancel',
];
var DESTRUCTIVE_INDEX = 3;
var CANCEL_INDEX = 4;

var ActionSheetExample = React.createClass({
getInitialState() {
return {
clicked: 'none',
};
},

render() {
return (
<View>
<Text onPress={this.showActionSheet} style={style.button}>
Click to show the ActionSheet
</Text>
<Text>
Clicked button at index: "{this.state.clicked}"
</Text>
</View>
);
},

showActionSheet() {
ActionSheetIOS.showActionSheetWithOptions({
options: BUTTONS,
cancelButtonIndex: CANCEL_INDEX,
destructiveButtonIndex: DESTRUCTIVE_INDEX,
},
(buttonIndex) => {
this.setState({ clicked: BUTTONS[buttonIndex] });
});
}
});

var ShareActionSheetExample = React.createClass({
getInitialState() {
return {
text: ''
};
},

render() {
return (
<View>
<Text onPress={this.showShareActionSheet} style={style.button}>
Click to show the Share ActionSheet
</Text>
<Text>
{this.state.text}
</Text>
</View>
);
},

showShareActionSheet() {
ActionSheetIOS.showShareActionSheetWithOptions({
url: 'https://code.facebook.com',
},
(error) => {
console.error(error);
},
(success, method) => {
var text;
if (success) {
text = `Shared via ${method}`;
} else {
text = 'You didn\'t share';
}
this.setState({text})
});
}
});

var style = StyleSheet.create({
button: {
marginBottom: 10,
fontWeight: 'bold',
}
});

exports.title = 'ActionSheetIOS';
exports.description = 'Interface to show iOS\' action sheets';
exports.examples = [
{
title: 'Show Action Sheet',
render() { return <ActionSheetExample />; }
},
{
title: 'Show Share Action Sheet',
render() { return <ShareActionSheetExample />; }
}
];
30 changes: 26 additions & 4 deletions Examples/UIExplorer/AdSupportIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,41 @@ var AdSupportIOSExample = React.createClass({
getInitialState: function() {
return {
deviceID: 'No IDFA yet',
hasAdvertiserTracking: 'unset',
};
},

componentDidMount: function() {
AdSupportIOS.getAdvertisingId(
this._onSuccess,
this._onFailure
this._onDeviceIDSuccess,
this._onDeviceIDFailure
);

AdSupportIOS.getAdvertisingTrackingEnabled(
this._onHasTrackingSuccess,
this._onHasTrackingFailure
);
},

_onHasTrackingSuccess: function(hasTracking) {
this.setState({
'hasAdvertiserTracking': hasTracking,
});
},

_onSuccess: function(deviceID) {
_onHasTrackingFailure: function(e) {
this.setState({
'hasAdvertiserTracking': 'Error!',
});
},

_onDeviceIDSuccess: function(deviceID) {
this.setState({
'deviceID': deviceID,
});
},

_onFailure: function(e) {
_onDeviceIDFailure: function(e) {
this.setState({
'deviceID': 'Error!',
});
Expand All @@ -58,6 +76,10 @@ var AdSupportIOSExample = React.createClass({
<Text style={styles.title}>Advertising ID: </Text>
{JSON.stringify(this.state.deviceID)}
</Text>
<Text>
<Text style={styles.title}>Has Advertiser Tracking: </Text>
{JSON.stringify(this.state.hasAdvertiserTracking)}
</Text>
</View>
);
}
Expand Down
30 changes: 30 additions & 0 deletions Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
147CED4C1AB3532B00DA3E4C /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 147CED4B1AB34F8C00DA3E4C /* libRCTActionSheet.a */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -70,6 +71,13 @@
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RCTGeolocation;
};
147CED4A1AB34F8C00DA3E4C /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RCTActionSheet;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
Expand All @@ -89,6 +97,7 @@
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = ../../Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -103,6 +112,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
147CED4C1AB3532B00DA3E4C /* libRCTActionSheet.a in Frameworks */,
134454601AAFCABD003F0779 /* libRCTAdSupport.a in Frameworks */,
134A8A2A1AACED7A00945AAE /* libRCTGeolocation.a in Frameworks */,
1341802C1AA9178B003F314A /* libRCTNetwork.a in Frameworks */,
Expand Down Expand Up @@ -135,6 +145,7 @@
1316A21D1AA397F400C0188E /* Libraries */ = {
isa = PBXGroup;
children = (
14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */,
13417FFA1AA91531003F314A /* ReactKit.xcodeproj */,
134454551AAFCAAE003F0779 /* RCTAdSupport.xcodeproj */,
134A8A201AACED6A00945AAE /* RCTGeolocation.xcodeproj */,
Expand Down Expand Up @@ -206,6 +217,14 @@
name = UIExplorer;
sourceTree = "<group>";
};
147CED471AB34F8C00DA3E4C /* Products */ = {
isa = PBXGroup;
children = (
147CED4B1AB34F8C00DA3E4C /* libRCTActionSheet.a */,
);
name = Products;
sourceTree = "<group>";
};
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -290,6 +309,10 @@
productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = 147CED471AB34F8C00DA3E4C /* Products */;
ProjectRef = 14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */;
},
{
ProductGroup = 134454561AAFCAAE003F0779 /* Products */;
ProjectRef = 134454551AAFCAAE003F0779 /* RCTAdSupport.xcodeproj */;
Expand Down Expand Up @@ -366,6 +389,13 @@
remoteRef = 134A8A241AACED6A00945AAE /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
147CED4B1AB34F8C00DA3E4C /* libRCTActionSheet.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTActionSheet.a;
remoteRef = 147CED4A1AB34F8C00DA3E4C /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
Expand Down
1 change: 1 addition & 0 deletions Examples/UIExplorer/UIExplorerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var EXAMPLES = [
require('./AppStateIOSExample'),
require('./AdSupportIOSExample'),
require('./AppStateExample'),
require('./ActionSheetIOSExample'),
];

var UIExplorerList = React.createClass({
Expand Down
49 changes: 49 additions & 0 deletions Libraries/ActionSheetIOS/ActionSheetIOS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule ActionSheetIOS
*/
'use strict';

var invariant = require('invariant');
var RCTActionSheetManager = require('NativeModulesDeprecated').RKActionSheetManager;

var ActionSheetIOS = {
showActionSheetWithOptions(options, callback) {
invariant(
typeof options === 'object' && options !== null,
'Options must a valid object'
);
invariant(
typeof callback === 'function',
'Must provide a valid callback'
);
RCTActionSheetManager.showActionSheetWithOptions(
options,
() => {}, // RKActionSheet compatibility hack
callback
);
},

showShareActionSheetWithOptions(options, failureCallback, successCallback) {
invariant(
typeof options === 'object' && options !== null,
'Options must a valid object'
);
invariant(
typeof failureCallback === 'function',
'Must provide a valid failureCallback'
);
invariant(
typeof successCallback === 'function',
'Must provide a valid successCallback'
);
RCTActionSheetManager.showShareActionSheetWithOptions(
options,
failureCallback,
successCallback
);
}
};

module.exports = ActionSheetIOS;
Loading

0 comments on commit c08243d

Please sign in to comment.