UIViewController classes on iOS and base
Activity on Android. View Controllers on both platforms are providing a straight forward API to create a base controller via dependency injection of the module name as well as initial props for rendering the root component represented from the module name. This allows to not have to subclass a base controller for every component that will be rendered. If dependency injection is not possible, the base controller classes also providing hooks for subclassing to provide great flexibility.
This project is currently in beta.
Core APIs are subject to change. We encourage people to try this library out and provide us feedback as we get it to a stable state.
$ npm install react-native-view-controller --save
Mostly automatic installation
$ react-native link react-native-view-controller
- In XCode, in the project navigator, right click
Add Files to [your project's name]
- Go to
- In XCode, in the project navigator, select your project. Add
libMSRReactNativeViewController.ato your project's
Link Binary With Libraries
- Run your project (
- Open up
import net.mischneider.MSRReactNativeViewControllerPackage;to the imports at the top of the file
new MSRReactNativeViewControllerPackage()to the list returned by the
- Append the following lines to
include ':react-native-view-controller' project(':react-native-view-controller').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-view-controller/android')
- Insert the following lines inside the dependencies block in
On iOS the base view controller is represented by the
// Create a MSRReactNativeViewController and push or present it on the current stack. It uses a MSRReactNativeBridgeManager as view provider.MSRReactNativeBridgeManager *bridgeManager = ;NSString *moduleName = ...; // Name of the root component that should be renderedNSDictionary *initialProperties = ...; // Some initial props that should be passed as initial props to the componentnMSRReactNativeViewController *reactNativeViewController = ;// Push or present the React Native view controller on the current navigation stack;
On Android the base view controller is represented by the
ReactNativeActivity and the
// Push a React Native Activity on the current stack.// Create an intent to for the React Native activity that should be presented. `this` is the current activity.Intent intent = new Intent(this, ReactNativeActivity.class);// Add the module name you would like to launch within the activityString moduleName = ...; // Module name of the root component that should be renderedintent.;// Add the launch options that will get passed down as initial props to the component represented by the module nameBundle options = ...; // Bundle that is passed as initial propsintent.;// Start the ReactNativeActivity;
Copyright 2018 Michael Schneider
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.