Skip to content

Commit

Permalink
Updates from Wed Feb 18
Browse files Browse the repository at this point in the history
- [reactnative] s/SpinnerIOS/ActivityIndicatorIOS/ | Dan Witte
- [react-packager] Add a non-persistent mode for static builds | Amjad Masad
- [React Native] Fix stored file rejection when initializing cache | Alex Akers
- [React Native] Consolidate network requests in image downloader | Alex Akers
- [React Native] Update RCTCache | Alex Akers
- Converted all low-hanging RKBridgeModules in FBReactKit to RCTBridgeModules | Nick Lockwood
  • Loading branch information
sahrens committed Feb 19, 2015
1 parent 89db1a6 commit c88a1cd
Show file tree
Hide file tree
Showing 22 changed files with 427 additions and 269 deletions.
6 changes: 3 additions & 3 deletions Examples/Movies/SearchScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var {
ListView,
ListViewDataSource,
ScrollView,
SpinnerIOS,
ActivityIndicatorIOS,
StyleSheet,
Text,
TextInput,
Expand Down Expand Up @@ -215,7 +215,7 @@ var SearchScreen = React.createClass({
if (!this.hasMore() || !this.state.isLoadingTail) {
return <View style={styles.scrollSpinner} />;
}
return <SpinnerIOS style={styles.scrollSpinner} />;
return <ActivityIndicatorIOS style={styles.scrollSpinner} />;
},

renderRow: function(movie: Object) {
Expand Down Expand Up @@ -290,7 +290,7 @@ var SearchBar = React.createClass({
onFocus={this.props.onFocus}
style={styles.searchBarInput}
/>
<SpinnerIOS
<ActivityIndicatorIOS
animating={this.props.isLoading}
style={styles.spinner}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule SpinnerExample
* @providesModule ActivityIndicatorExample
*/
'use strict';

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

var ToggleAnimatingSpinner = React.createClass({
var ToggleAnimatingActivityIndicator = React.createClass({
mixins: [TimerMixin],

getInitialState: function() {
Expand All @@ -38,25 +38,25 @@ var ToggleAnimatingSpinner = React.createClass({

render: function() {
return (
<SpinnerIOS
<ActivityIndicatorIOS
animating={this.state.animating}
style={[styles.centering, {height: 80}]}
size={SpinnerIOS.size.large}
size={ActivityIndicatorIOS.size.large}
/>
);
}
});

exports.framework = 'React';
exports.title = '<SpinnerIOS>';
exports.title = '<ActivityIndicatorIOS>';
exports.description = 'Animated loading indicators.';

exports.examples = [
{
title: 'Default (small, white)',
render: function() {
return (
<SpinnerIOS
<ActivityIndicatorIOS
style={[styles.centering, styles.gray, {height: 40}]}
color="white"
/>
Expand All @@ -68,10 +68,10 @@ exports.examples = [
render: function() {
return (
<View>
<SpinnerIOS
<ActivityIndicatorIOS
style={[styles.centering, {height: 40}]}
/>
<SpinnerIOS
<ActivityIndicatorIOS
style={[styles.centering, {backgroundColor: '#eeeeee', height: 40}]}
/>
</View>
Expand All @@ -83,10 +83,10 @@ exports.examples = [
render: function() {
return (
<View style={styles.horizontal}>
<SpinnerIOS color="#0000ff" />
<SpinnerIOS color="#aa00aa" />
<SpinnerIOS color="#aa3300" />
<SpinnerIOS color="#00aa00" />
<ActivityIndicatorIOS color="#0000ff" />
<ActivityIndicatorIOS color="#aa00aa" />
<ActivityIndicatorIOS color="#aa3300" />
<ActivityIndicatorIOS color="#00aa00" />
</View>
);
}
Expand All @@ -95,10 +95,10 @@ exports.examples = [
title: 'Large',
render: function() {
return (
<SpinnerIOS
<ActivityIndicatorIOS
style={[styles.centering, styles.gray, {height: 80}]}
color="white"
size={SpinnerIOS.size.large}
size={ActivityIndicatorIOS.size.large}
/>
);
}
Expand All @@ -108,20 +108,20 @@ exports.examples = [
render: function() {
return (
<View style={styles.horizontal}>
<SpinnerIOS
size={SpinnerIOS.size.large}
<ActivityIndicatorIOS
size={ActivityIndicatorIOS.size.large}
color="#0000ff"
/>
<SpinnerIOS
size={SpinnerIOS.size.large}
<ActivityIndicatorIOS
size={ActivityIndicatorIOS.size.large}
color="#aa00aa"
/>
<SpinnerIOS
size={SpinnerIOS.size.large}
<ActivityIndicatorIOS
size={ActivityIndicatorIOS.size.large}
color="#aa3300"
/>
<SpinnerIOS
size={SpinnerIOS.size.large}
<ActivityIndicatorIOS
size={ActivityIndicatorIOS.size.large}
color="#00aa00"
/>
</View>
Expand All @@ -131,7 +131,7 @@ exports.examples = [
{
title: 'Start/stop',
render: function() {
return <ToggleAnimatingSpinner />;
return <ToggleAnimatingActivityIndicator />;
}
},
];
Expand Down
2 changes: 1 addition & 1 deletion Examples/UIExplorer/UIExplorerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var EXAMPLES = [
require('./StatusBarIOSExample'),
require('./PointerEventsExample'),
require('./TouchableExample'),
require('./SpinnerExample'),
require('./ActivityIndicatorExample'),
require('./ScrollViewExample'),
];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule SpinnerIOS
* @providesModule ActivityIndicatorIOS
*/
'use strict';

Expand All @@ -25,7 +25,7 @@ var SpinnerSize = keyMirror({

var GRAY = '#999999';

var SpinnerIOS = React.createClass({
var ActivityIndicatorIOS = React.createClass({
mixins: [NativeMethodsMixin],

propTypes: {
Expand All @@ -39,8 +39,8 @@ var SpinnerIOS = React.createClass({
color: PropTypes.string,
/**
* The size of the spinner, must be one of:
* - SpinnerIOS.size.large
* - SpinnerIOS.size.small (default)
* - ActivityIndicatorIOS.size.large
* - ActivityIndicatorIOS.size.small (default)
*/
size: PropTypes.oneOf([SpinnerSize.large, SpinnerSize.small]),
},
Expand Down Expand Up @@ -101,4 +101,4 @@ var UIActivityIndicatorView = createReactIOSNativeComponentClass({
uiViewClassName: 'UIActivityIndicatorView',
});

module.exports = SpinnerIOS;
module.exports = ActivityIndicatorIOS;
2 changes: 1 addition & 1 deletion Libraries/react-native/react-native-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare module "react-native" {
declare var NavigatorItemIOS: ReactClass<any, any, any>;
declare var PixelRatio: ReactClass<any, any, any>;
declare var ScrollView: ReactClass<any, any, any>;
declare var SpinnerIOS: ReactClass<any, any, any>;
declare var ActivityIndicatorIOS: ReactClass<any, any, any>;
declare var StyleSheet: ReactClass<any, any, any>;
declare var Text: ReactClass<any, any, any>;
declare var TextInput: ReactClass<any, any, any>;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/react-native/react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var ReactNative = {
NavigatorIOS: require('NavigatorIOS'),
PixelRatio: require('PixelRatio'),
ScrollView: require('ScrollView'),
SpinnerIOS: require('SpinnerIOS'),
ActivityIndicatorIOS: require('ActivityIndicatorIOS'),
StatusBarIOS: require('StatusBarIOS'),
StyleSheet: require('StyleSheet'),
Text: require('Text'),
Expand Down
70 changes: 39 additions & 31 deletions ReactKit/Base/RCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ - (NSString *)description
RCTRemoteModulesByID = [[NSMutableDictionary alloc] init];

remoteModules = [[NSMutableDictionary alloc] init];
[RCTExportedMethodsByModule() enumerateKeysAndObjectsUsingBlock:^(NSString *moduleName, NSArray *rawMethods, BOOL *stop) {

[RCTBridgeModuleClasses() enumerateKeysAndObjectsUsingBlock:^(NSString *moduleName, Class moduleClass, BOOL *stop) {

NSArray *rawMethods = RCTExportedMethodsByModule()[moduleName];
NSMutableDictionary *methods = [NSMutableDictionary dictionaryWithCapacity:rawMethods.count];
[rawMethods enumerateObjectsUsingBlock:^(RCTModuleMethod *method, NSUInteger methodID, BOOL *stop) {
methods[method.JSMethodName] = @{
Expand All @@ -249,13 +250,15 @@ - (NSString *)description
@"moduleID": @(remoteModules.count),
@"methods": methods
};

Class cls = RCTBridgeModuleClasses()[moduleName];
if (RCTClassOverridesClassMethod(cls, @selector(constantsToExport))) {
module = [module mutableCopy];
((NSMutableDictionary *)module)[@"constants"] = [cls constantsToExport];

if (RCTClassOverridesClassMethod(moduleClass, @selector(constantsToExport))) {
NSDictionary *constants = [moduleClass constantsToExport];
if (constants.count) {
module = [module mutableCopy];
((NSMutableDictionary *)module)[@"constants"] = constants;
}
}
remoteModules[moduleName] = module;
remoteModules[moduleName] = [module copy];

// Add module lookup
RCTRemoteModulesByID[module[@"moduleID"]] = moduleName;
Expand Down Expand Up @@ -303,13 +306,13 @@ - (NSString *)description
// Add globally used methods
[JSMethods addObjectsFromArray:@[
@"Bundler.runApplication",
@"RCTDeviceEventEmitter.emit",
@"RCTEventEmitter.receiveEvent",
@"RCTEventEmitter.receiveTouches",
]];

// NOTE: these methods are currently unused in the OSS project
// @"Dimensions.set",
// @"RCTDeviceEventEmitter.emit",
// @"RCTNativeAppEventEmitter.emit",
// @"ReactIOS.unmountComponentAtNodeAndRemoveContainer",

Expand Down Expand Up @@ -376,10 +379,15 @@ - (instancetype)initWithJavaScriptExecutor:(id<RCTJavaScriptExecutor>)javaScript
_moduleInstances = [[NSMutableDictionary alloc] init];
[RCTBridgeModuleClasses() enumerateKeysAndObjectsUsingBlock:^(NSString *moduleName, Class moduleClass, BOOL *stop) {
if (_moduleInstances[moduleName] == nil) {
id<RCTBridgeModule> moduleInstance;
if ([moduleClass instancesRespondToSelector:@selector(initWithBridge:)]) {
_moduleInstances[moduleName] = [[moduleClass alloc] initWithBridge:self];
moduleInstance = [[moduleClass alloc] initWithBridge:self];
} else {
_moduleInstances[moduleName] = [[moduleClass alloc] init];
moduleInstance = [[moduleClass alloc] init];
}
if (moduleInstance) {
// If nil, the module doesn't support auto-instantiation
_moduleInstances[moduleName] = moduleInstance;
}
}
}];
Expand Down Expand Up @@ -522,22 +530,22 @@ - (void)_handleBuffer:(id)buffer
}

if (![buffer isKindOfClass:[NSArray class]]) {
RCTLogMustFix(@"Buffer must be an instance of NSArray, got %@", NSStringFromClass([buffer class]));
RCTLogError(@"Buffer must be an instance of NSArray, got %@", NSStringFromClass([buffer class]));
return;
}

NSArray *requestsArray = (NSArray *)buffer;
NSUInteger bufferRowCount = [requestsArray count];
NSUInteger expectedFieldsCount = RCTBridgeFieldResponseReturnValues + 1;
if (bufferRowCount != expectedFieldsCount) {
RCTLogMustFix(@"Must pass all fields to buffer - expected %zd, saw %zd", expectedFieldsCount, bufferRowCount);
RCTLogError(@"Must pass all fields to buffer - expected %zd, saw %zd", expectedFieldsCount, bufferRowCount);
return;
}

for (NSUInteger fieldIndex = RCTBridgeFieldRequestModuleIDs; fieldIndex <= RCTBridgeFieldParamss; fieldIndex++) {
id field = [requestsArray objectAtIndex:fieldIndex];
if (![field isKindOfClass:[NSArray class]]) {
RCTLogMustFix(@"Field at index %zd in buffer must be an instance of NSArray, got %@", fieldIndex, NSStringFromClass([field class]));
RCTLogError(@"Field at index %zd in buffer must be an instance of NSArray, got %@", fieldIndex, NSStringFromClass([field class]));
return;
}
}
Expand All @@ -549,7 +557,7 @@ - (void)_handleBuffer:(id)buffer
NSUInteger numRequests = [moduleIDs count];
BOOL allSame = numRequests == [methodIDs count] && numRequests == [paramsArrays count];
if (!allSame) {
RCTLogMustFix(@"Invalid data message - all must be length: %zd", numRequests);
RCTLogError(@"Invalid data message - all must be length: %zd", numRequests);
return;
}

Expand Down Expand Up @@ -578,30 +586,30 @@ - (BOOL)_handleRequestNumber:(NSUInteger)i
params:(NSArray *)params
{
if (![params isKindOfClass:[NSArray class]]) {
RCTLogMustFix(@"Invalid module/method/params tuple for request #%zd", i);
RCTLogError(@"Invalid module/method/params tuple for request #%zd", i);
return NO;
}

NSString *moduleName = RCTRemoteModulesByID[moduleID];
if (!moduleName) {
RCTLogMustFix(@"Unknown moduleID: %@", moduleID);
RCTLogError(@"Unknown moduleID: %@", moduleID);
return NO;
}

NSArray *methods = RCTExportedMethodsByModule()[moduleName];
if (methodID >= methods.count) {
RCTLogMustFix(@"Unknown methodID: %zd for module: %@", methodID, moduleName);
RCTLogError(@"Unknown methodID: %zd for module: %@", methodID, moduleName);
return NO;
}

RCTModuleMethod *method = methods[methodID];
NSUInteger methodArity = method.arity;
if (params.count != methodArity) {
RCTLogMustFix(@"Expected %tu arguments but got %tu invoking %@.%@",
methodArity,
params.count,
moduleName,
method.JSMethodName);
RCTLogError(@"Expected %tu arguments but got %tu invoking %@.%@",
methodArity,
params.count,
moduleName,
method.JSMethodName);
return NO;
}

Expand Down Expand Up @@ -663,13 +671,13 @@ - (BOOL)_handleRequestNumber:(NSUInteger)i
// TODO: it seems like an error if the param doesn't respond
// so we should probably surface that error rather than failing silently
#define CASE(_value, _type, _selector) \
case _value: \
if ([param respondsToSelector:@selector(_selector)]) { \
_type value = [param _selector]; \
[invocation setArgument:&value atIndex:argIdx]; \
shouldSet = NO; \
} \
break;
case _value: \
if ([param respondsToSelector:@selector(_selector)]) { \
_type value = [param _selector]; \
[invocation setArgument:&value atIndex:argIdx]; \
shouldSet = NO; \
} \
break;

CASE('c', char, charValue)
CASE('C', unsigned char, unsignedCharValue)
Expand Down Expand Up @@ -698,7 +706,7 @@ - (BOOL)_handleRequestNumber:(NSUInteger)i
[invocation invoke];
}
@catch (NSException *exception) {
RCTLogMustFix(@"Exception thrown while invoking %@ on target %@ with params %@: %@", method.JSMethodName, target, params, exception);
RCTLogError(@"Exception thrown while invoking %@ on target %@ with params %@: %@", method.JSMethodName, target, params, exception);
}
});

Expand Down
Loading

0 comments on commit c88a1cd

Please sign in to comment.