Skip to content

Instantly share code, notes, and snippets.

@dsibiski
Last active September 18, 2015 01:25
Show Gist options
  • Save dsibiski/d46cf47043d354132dc7 to your computer and use it in GitHub Desktop.
Save dsibiski/d46cf47043d354132dc7 to your computer and use it in GitHub Desktop.
Wrap platform specific components and let the packager do the work. The packager excludes "*.ios.js" files for Android development and vice versa for iOS development.
// Spinner.ios.js
var React = require('react-native');
var {
ActivityIndicatorIOS,
} = React;
class Spinner extends React.Component {
render() {
return (
<ActivityIndicatorIOS
animating={this.props.isLoading}
size='large' />
);
}
}
module.exports = Spinner;
// Spinner.android.js
var React = require('react-native');
var {
ProgressBarAndroid,
View,
} = React;
class Spinner extends React.Component {
render() {
if (this.props.isLoading) {
return (
<View style={{alignItems: 'center'}}>
<ProgressBarAndroid styleAttr="Large"/>
</View>
);
} else {
return ( <View /> );
}
}
}
module.exports = Spinner;
// MyApp.js
var React = require('react-native');
var Spinner = require('./Spinner');
class MyApp extends React.Component {
render() {
return (
<Spinner animating={true}/>
);
}
});
module.exports = MyApp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment