Skip to content

Instantly share code, notes, and snippets.

@kenwheeler
Last active May 5, 2017 15:05
Show Gist options
  • Save kenwheeler/b20ea372efcc52adf905 to your computer and use it in GitHub Desktop.
Save kenwheeler/b20ea372efcc52adf905 to your computer and use it in GitHub Desktop.
import React from "react";
const RN = React;
export const PropTypes = React.PropTypes;
RN.StyleSheet = {
create: (style) => style
};
const createComponent = (type) => {
return React.createClass({
displayName: type,
propTypes: {
children: React.PropTypes.node
},
render() {
return <div {...this.props}>{this.props.children}</div>;
}
});
};
RN.View = createComponent("View");
RN.Text = createComponent("Text");
RN.ActivityIndicatorIOS = createComponent("ActivityIndicatorIOS");
RN.Image = createComponent("Image");
RN.TouchableHighlight = createComponent("TouchableHighlight");
RN.ScrollView = createComponent("ScrollView");
export default RN;
@joemckie
Copy link

joemckie commented Aug 20, 2016

As react-native has named exports, the following would actually return undefined, and React.createElement type warnings:

import {
  View,
  Text
} from 'react-native';

You could fix this by providing the same named exports in this mock:

const View = RN.View = createComponent("View");
// ...etc

export {
  RN.View,
  RN.Text,
  RN.ActivityIndicatorIOS,
  RN.Image,
  RN.TouchableHighlight,
  RN.ScrollView
};

@fmedinac
Copy link

fmedinac commented May 5, 2017

@joemckie you mean:

export {
  View,
  Text,
  ActivityIndicatorIOS,
  Image,
  TouchableHighlight,
  ScrollView,
  StyleSheet
};

Right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment