Skip to content

[ReactNative] Export EdgeInsetsPropType and PointPropType - #262

Closed
ide wants to merge 1 commit into
react:masterfrom
ide:exports
Closed

[ReactNative] Export EdgeInsetsPropType and PointPropType#262
ide wants to merge 1 commit into
react:masterfrom
ide:exports

Conversation

@ide

@ideide commented Mar 26, 2015

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

react/react#3221

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

Copy link
Copy Markdown
ContributorAuthor

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.jsmodule.exports={React: require('React'),// react native components};

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

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

Copy link
Copy Markdown
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');// goodvarReact=require('react-native');React.createClass// bad, only in React.ReactvarReactNative=require('react-native');ReactNative.React.createClass// good

Copy link
Copy Markdown
ContributorAuthor

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:

varReact=require('react-native');varNavigator=require('react-native-navigator');varVibration=require('react-native-vibration');
...
render(){return<viewstyle={styles.container}><text>hi</text></view>;}
...
varstyles=React.createStyleSheet({container: {flex: 1}});

Copy link
Copy Markdown
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

varReact=require('react-native');varNavigator=require('react-native-navigator');varVibration=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:

varReact=require('react-native/react');varNavigator=require('react-native/navigator');varVibration=require('react-native/vibration');

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

@ide
ideforce-pushed the exports branch 2 times, most recently from 89e62f2 to c7d9d3bCompareApril 6, 2015 19:40
@facebook-github-botfacebook-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
ideforce-pushed the exports branch 4 times, most recently from 213cb43 to 8de56ccCompareApril 15, 2015 20:59
@ide

ide commented Apr 15, 2015

Copy link
Copy Markdown
ContributorAuthor

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

@ide
ideforce-pushed the exports branch 2 times, most recently from c3a8f7a to 2f7da3bCompareApril 28, 2015 01:24
@ide
ideforce-pushed the exports branch 2 times, most recently from 55c9ee9 to 5fc2943CompareMay 8, 2015 21:51
@ericvicenti

Copy link
Copy Markdown
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

ide commented May 12, 2015

Copy link
Copy Markdown
ContributorAuthor

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

@ideide changed the title [Exports] Expose more modules for authors of custom components[ReactNative] Export EdgeInsetsPropType and PointPropTypeMay 30, 2015
@sahrens

Copy link
Copy Markdown
Contributor

LGTM - @ericvicenti: can you import and land?

@sahrenssahrens assigned sahrens and unassigned ericvicentiJun 11, 2015
@sahrens

Copy link
Copy Markdown
Contributor

Actually I'll just take it.

@sahrens

Copy link
Copy Markdown
Contributor

@facebook-github-bot import

@facebook-github-bot

Copy link
Copy Markdown
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.
Closesreact#262
Github Author: James Ide <ide@jameside.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
@ideide closed this in 4564726Jun 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
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis 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

@ide@ericvicenti@sahrens@facebook-github-bot@sophiebits@vjeux