Commit Graph

36 Commits

Author SHA1 Message Date
Christian Brevik f426a83d1b Add props for overriding native component
Summary:
Opening a new PR for #10946 (see discussion there).

This PR builds upon #14775 (iOS ViewManager inheritance) and #14261 (more extensible Android WebView).

**Motivation**
When `WebView.android.js` and `WebView.ios.js` use `requireNativeComponent`, they are hard-coded to require `RCTWebView`. This means if you want to re-use the same JS-logic, but require a custom native WebView-implementation, you have to duplicate the entire JS-code files.

The same is true if you want to pass through any custom events or props, which you want to set on the custom native `WebView`.

What I'm trying to solve with this PR is to able to extend native WebView logic, and being able to re-use and extend existing WebView JS-logic.

This is done by adding a new `nativeConfig` prop on WebView. I've also moved the  extra `requireNativeComponent` config to `WebView.extraNativeComponentConfig` for easier re-use.

**Test plan**
jacobp100 has been kind enough to help me with docs for this new feature. So that is part of the PR and can be read for some information.

I've also created an example app which demonstrates how to use this functionality: https://github.com/cbrevik/webview-native-config-example

If you've implemented the native side as in the example repo above, it should be fairly easy to use from JavaScript like this:
```javascript
import React, { Component, PropTypes } from 'react';
import { WebView, requireNativeComponent, NativeModules } from 'react-native';
const { CustomWebViewManager } = NativeModules;

export default class CustomWebView extends Component {
  static propTypes = {
    ...WebView.propTypes,
    finalUrl: PropTypes.string,
    onNavigationCompleted: PropTypes.func,
  };

  _onNavigationCompleted = (event) => {
    const { onNavigationCompleted } = this.props;
    onNavigationCompleted && onNavigationCompleted(event);
  }

  render() {
    return (
      <WebView
        {...this.props}
        nativeConfig={{
          component: RCTCustomWebView,
          props: {
            finalUrl: this.props.finalUrl,
            onNavigationCompleted: this._onNavigationCompleted,
          },
          viewManager: CustomWebViewManager
        }}
      />
    );
  }
}

const RCTCustomWebView = requireNativeComponent(
  'RCTCustomWebView',
  CustomWebView,
  WebView.extraNativeComponentConfig
);
```

As you see, you require the custom native implementation at the bottom, and send in that along with any custom props with the `nativeConfig` prop on the `WebView`. You also send in the `viewManager` since iOS requires that for `startLoadWithResult`.

**Discussion**
As noted in the original PR, this could in principle be done with more React Native components, to make it easier for the community to re-use and extend native components.
Closes https://github.com/facebook/react-native/pull/15016

Differential Revision: D5701280

Pulled By: hramos

fbshipit-source-id: 6c3702654339b037ee81d190c623b8857550e972
2017-09-19 16:01:02 -07:00
Ian Hill 3ceb20de74 Minor documentation correction for exposing native iOS components
Summary:
Minor documentation correction for the native components iOS API section.

Before: "Sometimes your native component will have some special properties that you don't want to them to be part of the API"

After: "Sometimes your native component will have some special properties that you don't want to be part of the API"

Confirm section renders correctly via markdown.
Closes https://github.com/facebook/react-native/pull/15914

Reviewed By: TheSavior

Differential Revision: D5817146

Pulled By: buymeasoda

fbshipit-source-id: 075441cf7f5f23a4ca512bae48ca8fc319762b1e
2017-09-12 13:51:55 -07:00
Petr Bela cdf1b0e5d5 Note about flex
Summary:
Hopefully, this will save an hour of WTFs for the next reader.
Closes https://github.com/facebook/react-native/pull/14876

Differential Revision: D5385881

Pulled By: hramos

fbshipit-source-id: 56961e8a5eb3b6fae4f92c7fb9fea1e1147a3521
2017-08-16 23:44:50 -07:00
Tieme van Veen 94b6cda8a7 Docs: Updated iOS Component Guide
Summary:
Follow up on https://github.com/facebook/react-native/issues/14436

hramos:
>  MapViewIOS was removed a couple of versions ago. No one has touched this guide in a while, so unless someone volunteers to get it back up to date, we'll probably end up removing it from the docs.

I'm volunteering to get it back up to date!

- Fixed broken code examples
- Swapped out `pitchEnabled` for `zoomEnabled`, needs less explaining and it's easier to test on a simulator.
- Renamed RNTMap to RNTMapView for clarity.
- Renamed inconsistent `onChange`s to onRegionChange`.
- Swapped out 'vending' for 'exposing'.

I wasn't really sure about the last 3 points. I think it's more clear like this, but please review.

I'll add some review comments as well.
Closes https://github.com/facebook/react-native/pull/14991

Differential Revision: D5416319

Pulled By: hramos

fbshipit-source-id: bc70942a66acc5e3967b245af8271a1d2465ab60
2017-07-19 15:31:29 -07:00
Tieme van Veen e57655274d Fix 14436 - Docs: ios-native-ui-guide 'RNTMap' -> 'MKMapView' fix
Summary:
Quick fix for https://github.com/facebook/react-native/issues/14436
Closes https://github.com/facebook/react-native/pull/14982

Differential Revision: D5409794

Pulled By: javache

fbshipit-source-id: ea59a9a11b689459e68c05a92095fdcee1da717f
2017-07-12 14:50:32 -07:00
Tieme van Veen c41b5a02f2 Docs: ios-native-ui-guide RCTConvert categories edit
Summary:
I was struggling a bit with the [iOS Native UI Components tutorial](https://facebook.github.io/react-native/docs/native-components-ios.html#content).

As noted here it's outdated. https://github.com/facebook/react-native/issues/14436

In my opinion, these steps are more clear when the header files are also included in the example. Besides that, the tutorial can use the already existing `RCTConvert+CoreLocation` category for simplicity.
Closes https://github.com/facebook/react-native/pull/14983

Differential Revision: D5409803

Pulled By: javache

fbshipit-source-id: f7fe1d2b542e8df602dc0f0636efb4d764090811
2017-07-12 14:09:55 -07:00
Seth Fitzsimmons 8e9322c65e react@16 did away with PropTypes; require prop-types instead
Summary:
react@16 (a peerDependency) did away with the PropTypes export in favor of the prop-types module.

This updates all of the remaining references to `React.PropTypes`.
Closes https://github.com/facebook/react-native/pull/14641

Differential Revision: D5287167

Pulled By: javache

fbshipit-source-id: a917e29aa0e5470260568995dfe97f5528ec265e
2017-06-22 13:49:57 -07:00
Hector Ramos 0a6935618c Add support for syntax highlighting for languages other than JS
Summary:
The current website defaults to using JavaScript for any code block, regardless of language tag. This PR adds syntax highlighting support by passing the necessary language prop and by adding any missing languages to Marked.js.

Depends on #14212, #14065
Closes https://github.com/facebook/react-native/pull/14215

Differential Revision: D5149897

Pulled By: hramos

fbshipit-source-id: 95a817af2168d5743c75dd1ac030d399a68fb93c
2017-05-30 14:36:06 -07:00
Hector Ramos b1ecb84c97 Standardize on using AwesomeProject for AppRegistry calls.
Summary:
We've noticed that many newcomers paste sample code straight into a project created using `react-native init AwesomeProject`, but the sample code assumes the user is creating a new project for each example. This PR makes it so that these samples can be pasted into the same project from the Getting Started.
Closes https://github.com/facebook/react-native/pull/14264

Differential Revision: D5149746

Pulled By: hramos

fbshipit-source-id: cae95ab5b7baf64ddd9fe12d342ad05f785bb381
2017-05-30 14:20:42 -07:00
sunnylqm 3a86b4fcb6 add missing props
Summary: Closes https://github.com/facebook/react-native/pull/13717

Differential Revision: D4978002

Pulled By: javache

fbshipit-source-id: 685bb3bf207c858302c74de4cc711b526a80d894
2017-05-01 06:03:20 -07:00
sebasbad 0f025df582 Update NativeComponentsIOS.md
Summary:
Updated map view example to correct and extend on change event management

Thanks for submitting a pull request! Please provide enough information so that others can review your pull request:

> **Unless you are a React Native release maintainer and cherry-picking an *existing* commit into a current release, ensure your pull request is targeting the `master` React Native branch.**

Explain the **motivation** for making this change. What existing problem does the pull request solve?

Prefer **small pull requests**. These are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it.

**Test plan (required)**

Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI.

Make sure tests pass on both Travis and Circle CI.

**Code formatting**

Look around. Match the style of the rest of the codebase. See also the simple [style guide](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#style-guide).

For more info, see the ["Pull Requests" section of our "Contributing" guidelines](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests).
Closes https://github.com/facebook/react-native/pull/12759

Differential Revision: D4962286

Pulled By: hramos

fbshipit-source-id: 92cc41f100616d3b5633603cf69850ebc9fc33b2
2017-04-28 05:56:58 -07:00
Hector Ramos c503dae446 Merge Android UI Performance into Performance doc, reorder sidebar
Summary:
Doing some cleanup in preparation for CRNA.
Recommend `FlatList` and React Navigation for perf.
Tag docs that may only apply to apps ejected from CRNA. Currently has no effect.
Closes https://github.com/facebook/react-native/pull/12692

Differential Revision: D4654077

Pulled By: hramos

fbshipit-source-id: 1245d80d66e37d9dca9e9daf23e8b93c65cd1bf7
2017-03-06 10:10:04 -08:00
Héctor Ramos fab09922cd fix duplicate symbols error in the Creating Native UI Component docs
Summary:
When creating Native UI Component per docs, it results in duplicate symbols error as explained in issue #12404

Instead of using RCT prefix, it is suggested to use RN prefix to avoid any duplicate symbols.
Closes https://github.com/facebook/react-native/pull/12523

Differential Revision: D4608532

Pulled By: hramos

fbshipit-source-id: 353cfee4bf2cea30706863af51cabe11e9394222
2017-02-23 16:45:39 -08:00
Seong-hyun, Oh 4ff659345c Update NativeComponentsIOS.md
Summary:
Only NativeComponentsIOS.md documentation changed.

Closes https://github.com/facebook/react-native/pull/12012

Differential Revision: D4452008

Pulled By: ericvicenti

fbshipit-source-id: 9ee748165a4efc9f987c5cadff8a21ab17f971c6
2017-01-23 14:43:28 -08:00
Neil Sarkar 2e4be1c2c9 Update NativeComponentsIOS.md
Summary:
Documentation-only change.

Reflects reference change from `RCTViewManager.h` to `React/RCTViewManager.h`
Closes https://github.com/facebook/react-native/pull/11756

Differential Revision: D4392028

Pulled By: ericvicenti

fbshipit-source-id: 7655817b0660738b8e45d18a5eda04f029259c5f
2017-01-09 00:13:33 -08:00
Joel Marcey b1e49832ef Make prev links work in guides and APIs.
Summary:
We had rendering support for prev links, but we never had any previous links in our metadata. Only next links. This adds that support to both Guides and APIs.

**For guides**: `previous` is manually inserted into the metadata of the actual markdown file.
**For APIs/Components**: `previous` is established via code within `extractDocs.js`

> This isn't totally perfect. For example, the transition from the last guide to the first API/component has a next link from the guide, but not a previous link from the API since the way you get the previous links are different from guides and APIs. But this gets us really close.
Closes https://github.com/facebook/react-native/pull/8754

Differential Revision: D3557972

Pulled By: hramos

fbshipit-source-id: e270bb51e7a4f59f61dad28ae0928d27d0af3d4a
2016-07-13 14:58:27 -07:00
Jean Regisser 0045e07928 Updated iOS native UI component events documentation
Summary:
Documentation on iOS about triggering events from native components was outdated.

Let me know what you think.
Closes https://github.com/facebook/react-native/pull/6739

Differential Revision: D3240665

Pulled By: mkonicek

fb-gh-sync-id: f62d52bebd58aae6f93388734338ef74ae536ec5
fbshipit-source-id: f62d52bebd58aae6f93388734338ef74ae536ec5
2016-04-29 05:11:59 -07:00
Sebastian Markbage 6f43d1f2cb Codemod import React from 'react-native'
Reviewed By: spicyj

Differential Revision: D3223162

fb-gh-sync-id: 0b1af846afe17cdf8b2c2ca7f31f1197cde752c0
fbshipit-source-id: 0b1af846afe17cdf8b2c2ca7f31f1197cde752c0
2016-04-25 22:08:46 -07:00
Aaron Connolly 67b138e77c Added a small note about an issue I ran into vending a simple `UIView?
Summary:?` instance to React Native. The layout system suppressed the values for `frame` and `backgroundColor` on my simple view and it wasn't clear why. After some debugging and hacking it became apparent that React Native needed to adjust those properties during layout. The workaround I found was to wrap my custom `UIView` in another `UIView` instance.

**Motivation**

When attempting to bridge a simple 100x100 red background `UIView` to ReactNative I could not get the view to show up as a `RCTView`. The view was there, but it was not 100x100 and it didn't have a red background. After a couple hours of poking around and debugging the call stacks on `setBackgroundColor` and `setFrame` it became apparent that React Native calls those messages on your `UIView` and sends new values. This is likely because of the layout system React Native uses.

I was encouraged to provide a small comment in the documentation if I thought others might find it useful. This PR is an attempt to provide a note in the documentation
Closes https://github.com/facebook/react-native/pull/6786

Differential Revision: D3133093

fb-gh-sync-id: 77d895f2f8e09978d283ee9e3193ee68cc5a7cb8
fbshipit-source-id: 77d895f2f8e09978d283ee9e3193ee68cc5a7cb8
2016-04-04 04:36:19 -07:00
Mateusz Zatorski 3ae99d0fea replace require with es6 import in docs
Reviewed By: svcscm

Differential Revision: D2936839

fb-gh-sync-id: 7a921709a37de5e9aadf324d5438d51851326348
shipit-source-id: 7a921709a37de5e9aadf324d5438d51851326348
2016-02-14 15:03:34 -08:00
Nick Lockwood 9d0242fdc3 Replace direct access of NativeModules.UIManager with require('UIManager')
Summary:
public
Due to the cross-platform polyfills we have added (and will add in future) to `UIManager.js`, accessing UIManager directly via NativeModules instead of importing the wrapper is discouraged.

This diff fixes a few places where we were doing this inside our own modules.

Note: As a general policy, we should avoid accessing modules via NativeModules anyway. Using wrapper classes allows us to provide static declarations for all the native methods and properties, which can be checked at build time by flow. If we access the modules directly, those interfaces are only known at runtime.

Reviewed By: vjeux

Differential Revision: D2881300

fb-gh-sync-id: 6737358ea8ea6d722cc1941a4b9fa0123a87fc29
2016-01-30 07:36:34 -08:00
sunnylqm 72a08c11c6 remove broken link 2015-12-31 11:41:49 +08:00
Nikita Gusakov e55b373a61 Split iOS and Android docs into different categories 2015-09-18 20:54:05 +03:00
Spencer Ahrens bb79d034d2 Add comments about `nativeOnly` props 2015-09-15 10:37:48 -07:00
Martin Konicek 42eb5464fd Release React Native for Android
This is an early release and there are several things that are known
not to work if you're porting your iOS app to Android.

See the Known Issues guide on the website.

We will work with the community to reach platform parity with iOS.
2015-09-14 18:13:39 +01:00
Martin Konicek 01911e5e06 [docs] Make it clear which Guides are platform-specific
This is in preparation for open sourcing React Native for Android.
Also add hyphens to URLs for consistency. This can break people's
browser bookmarks but it's better to be consistent and we can
redirect to docs: https://github.com/facebook/react-native/issues/2137

Test plan: Ran the website locally using `cd website; npm start`
and checked all pages render correctly.
http://i.imgur.com/RrPNgRr.png

Will update "Getting Started", "Tutorial", "Debugging" and
"Testing" separately.
2015-07-27 18:17:54 +01:00
Amjad Masad 82ca3364c6 Don't encourage the use of internal modules 2015-06-30 13:12:47 -07:00
Brent Vatne e2c6060226 [Docs] Add DirectManipluation guide, which explains setNativeProps 2015-06-17 21:43:39 -07:00
Jehan c4457f8e6f Update NativeComponentsIOS.md 2015-06-03 00:34:25 -07:00
Brent Vatne ffcdf21004 [Docs] Clarify the variables provided to RCT_CUSTOM_VIEW_PROPERTY body 2015-05-24 09:35:59 -07:00
James Ide 69db752067 Move requireNativeComponent call below the complete MapView definition
requireNativeComponent should be called after the wrapper component is fully defined, including its static properties.
2015-05-13 21:05:50 -07:00
Zhao Han 85a6734387 Update link in Native UI Components (iOS) guide
Update the event mapping link: update line number
2015-05-13 10:08:38 -05:00
James Ide 0e3d627ff0 Fix some typos in NativeComponentsIOS.md
Fixed some syntax errors and tidied up the sample code.
2015-04-30 00:39:37 -07:00
Spencer Ahrens f89bcacd86 Add missing 'and' in docs. 2015-04-29 15:42:30 -07:00
Spencer Ahrens 8efe148f07 Fix bullet spacing for website.
GitHub markdown rendered it fine, but it was all mashed inline on the website without the extra break.
2015-04-29 15:41:17 -07:00
Spencer Ahrens c5d367ad39 Add Native Components guide. 2015-04-21 16:22:32 -07:00