Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ReactNative] Export EdgeInsetsPropType and PointPropType #262

Closed
wants to merge 1 commit into from

Conversation

ide
Copy link
Contributor

@ide ide commented Mar 26, 2015

Added some more exports to React that are either necessary or often useful for component authors.

//
var ReactNative = Object.assign(Object.create(require('React')), {
var ReactNative = Object.assign(Object.create(React), {
React,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @vjeux - any reason not to do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a thread on react about this. The main counter argument is that it introduces a cyclic dependency so it's a nightmare to console.log. But, this would make the require boilerplate shorter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log should handle cycles anyway so you can debug cyclic objects. That said I think there isn't a cycle for ReactNative since the Object.create(React) is not the React object, so assigning React to the clone doesn't introduce a cycle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

facebook/react#3221

Personally this strikes me as a little weird and I don't want it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this instance there's no cycle since react-native is exporting React along with some other native extensions. Another option is remove the Object.assign bit and just have:

// react-native.js
module.exports = {
  React: require('React'),
  // react native components
};

and then have the pattern for using it be var {React, View} = require('react-native') or alternatively

var ReactNative = require('react-native');
var {React, View} = ReactNative;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were going this way, we should probably not extend from React.

var {React, View} = require('react-native'); // good

var React = require('react-native');
React.createClass // bad, only in React.React

var ReactNative = require('react-native');
ReactNative.React.createClass // good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vjeux I think so too. Perhaps the question we should answer is whether destructuring assignment is the right pattern for the react-native module.

In web React's case, we usually write var React = require('react') and JSX handles the basic DOM components, so we don't write var {div, span} = require('react');.

With React Native, does it make more sense to lowercase the basic components like View, Text, Image, and maybe Touchable* and let JSX handle them? Other components and libraries like Navigator and Vibration would be published as separate packages, which helps reduce the size of the JS bundle as well. The code would look like:

var React = require('react-native');
var Navigator = require('react-native-navigator');
var Vibration = require('react-native-vibration');
...
render() {
  return <view style={styles.container}><text>hi</text></view>;
}
...
var styles = React.createStyleSheet({
  container: {flex: 1}
}); 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many issues with

var React = require('react-native');
var Navigator = require('react-native-navigator');
var Vibration = require('react-native-vibration');

The first one is that we're going to run into naming conflicts with npm. Someone else will steal a name that we want and we're going to either reach out and negotiate or use a less ideal one.

Then, you're running into crazy dependency issues where you have different versions of all of those plugins and conflicts. We really want to ship one bundle where everything is in sync for the core components.

One idea I had is:

var React = require('react-native/react');
var Navigator = require('react-native/navigator');
var Vibration = require('react-native/vibration');

Everything is bundled together, no namespace clash and we don't bundle things that we don't use

@ide ide force-pushed the exports branch 2 times, most recently from 89e62f2 to c7d9d3b Compare April 6, 2015 19:40
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 7, 2015
@ide ide force-pushed the exports branch 4 times, most recently from 213cb43 to 8de56cc Compare April 15, 2015 20:59
@ide
Copy link
Contributor Author

ide commented Apr 15, 2015

I removed the React self-export so now this is just the struct prop types and the static renderers.

@ide ide force-pushed the exports branch 2 times, most recently from c3a8f7a to 2f7da3b Compare April 28, 2015 01:24
@ide ide force-pushed the exports branch 2 times, most recently from 55c9ee9 to 5fc2943 Compare May 8, 2015 21:51
@ericvicenti
Copy link
Contributor

StaticContainer and StaticRenderer are both considered deprecated techniques.

A more modern approach will do rendering early, and store the descriptor (the result of the render) in the component state, and get inlined in the render function.

@ide
Copy link
Contributor Author

ide commented May 12, 2015

Removed Static helpers, it's now just prop types for EdgeInsets and Point.

@ide ide changed the title [Exports] Expose more modules for authors of custom components [ReactNative] Export EdgeInsetsPropType and PointPropType May 30, 2015
@sahrens
Copy link
Contributor

sahrens commented Jun 11, 2015

LGTM - @ericvicenti: can you import and land?

@sahrens sahrens assigned sahrens and unassigned ericvicenti Jun 11, 2015
@sahrens
Copy link
Contributor

sahrens commented Jun 11, 2015

Actually I'll just take it.

@sahrens
Copy link
Contributor

sahrens commented Jun 11, 2015

@facebook-github-bot import

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1057649787583002/int_phab to review.

sahrens pushed a commit to sahrens/react-native that referenced this pull request Jun 12, 2015
Summary:
Added some more exports to React that are either necessary or often useful for component authors.

Closes facebook#262
Github Author: James Ide <ide@jameside.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
@ide ide closed this in 4564726 Jun 12, 2015
@ide ide deleted the exports branch June 25, 2015 18:12
mganandraj pushed a commit to mganandraj/react-native that referenced this pull request Mar 26, 2020
* Add support for macOS legacy scroller system setting.

* Add missing comment.  Whitespace cleanup

* Add locals

* Fixed ] in comment
jfrolich pushed a commit to jfrolich/react-native that referenced this pull request Apr 22, 2020
ayushjainrksh referenced this pull request in MLH-Fellowship/react-native Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants