Magic!
class Foo extends React.Component {
render() {
return (
<a href="//hooli.xyz">
<p>some text</p>
</a>
);
}
}
Not entirely...
class FooNative extends React.Component { _handlePress() { const platformMethod = Platform.OS === 'ios' ? LinkingIOS : IntentAndroid; platformMethod.openURL('https://hooli.xyz'); } render(){ return ( <TouchableHighlight onPress={this._handlePress}> <Text>some text</Text> </TouchableHighlight> ); } }
import React from 'react-native';
const { Image, Text, View, AppRegistry } = React;
class MyApp extends React.Component{
render() {
return (
<View style={styles.row}>
<Image source={{uri: 'http://www.feistees.com/wp-content/uploads/2014/05/squpd.jpg'}} style={styles.image} />
<View style={styles.text}>
<Text style={styles.title}>React Native </Text>
<Text style={styles.subtitle}>Build high quality mobile apps using React </Text>
</View>
</View>
);
}
});
AppRegistry.registerComponent('Pied_Piper', () => MyApp);
react-native run-android # (or through XCode for iOS)
adb logcat | grep ReactNative
adb logcat *:S ReactNative:V ReactNativeJS:V # from react-native docs
<Navigator
initialRoute={Routes.Login()}
renderScene={this.renderScene}
navigationBar={
<Navigator.NavigationBar
style={styles.navbar}
routeMapper={RouteMapper} />
}
/>
<Router navigationBarStyle={styles.navbar}>
<Schema name="default" sceneConfig={Navigator.SceneConfigs.FloatFromRight}
renderTitle={() => <NavbarTitle />} />
<Schema name="tab" type="switch" />
<Route name="main" type="replace" schema="default">
<Router footer={TabBar} tabBarStyle={styles.tabbar}>
<Route name="tab1" component={Tab1} schema="tab" icon={TabIcon} />
<Route name="tab2" component={Tab2} schema="tab" icon={TabIcon} />
<Route name="tab3" component={Tab3} schema="tab" icon={TabIcon} />
</Router>
</Route>
</Router>
Has to be done more often than you would think!
MyNativeModule.java
@Override
public String getName() {
return "ThisModule";
}
@ReactMethod
public void doCoolStuff() {
System.out.print("Shw");
for(int i=1; i<999; i++) {
System.out.print("a");
}
System.out.println("g");
}
MyNativePackage.java
@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new MyNativeModule(reactContext));
return modules;
}
MainActivity.java
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new MyNativePackage()
);
}
import { NativeModules } from 'react-native';
NativeModules.ThisModule.doCoolStuff();
const styles = StyleSheet.create({
dafont: {
backgroundColor: '#FF7F00',
},
});
<Text style={styles.dafont}>This Guy!</Text>
Custom implementation of Flexbox
export function extendStylesheet(stylesheet) {
return StyleSheet.create(_.merge(globalStyles, stylesheet));
}
npm install react-native-extended-stylesheet --save
EStyleSheet.build({
textColor: '#FF7F00' // pass variables for styling
});
const styles = EStyleSheet.create({
column: {
width: '10%' // percentage of screen width
},
text: {
color: '$textColor', // use variable $textColor
fontSize: '3rem' // use relative unit - CSS3 rem
}
});
export default Map({
FONT_COLOUR: '#FF7F00',
FOOTER_HEIGHT: 50
});
export const FONT_COLOUR = '#FF7F00';
export const FOOTER_HEIGHT = 50;
const styles = StyleSheet.create({
darkFont: {
backgroundColor: GlobalStyles.get('FONT_COLOUR'),
},
});
Wait... Is this actually a terrible idea? I don't know. Maybe.
test-helper.js
require('react-native-mock/mock');
test-helper.js
mockery.registerMock('react-native-router-flux', require(MOCKS_DIR + '/react-native-router-flux'));
UI!
The best solution
Find another solution?
Contribute!
Tests for Native Code?