Git Product home page Git Product logo

react-native-android-extras's Introduction

React Native Android Extras

Problem

You cannot pass extras from Android to React Native JS module, by using only builder. But IOS have this ability, https://facebook.github.io/react-native/docs/communication-ios.html.

Usage

JavaScript

import { NativeModules } from 'react-native'
import {
    Text,
    View,
} from 'react-native';
class HelloWorld extends React.Component{
    render(){
         var  { page_name } = NativeModules.ReactIntentExtras;
        //TODO Initialize store or something with extras
       
        return (
            <Text>
                {page_name}
            </Text>
        );
    }
}
AppRegistry.registerComponent('HelloWorld', () => HelloWorld);

Java

//https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler {
    private ReactRootView mReactRootView;
    private ReactInstanceManager mReactInstanceManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //Init extras
        HashMap<String,Object> extras = new HashMap<>();
        extras.put("page_name","Football team");

        mReactRootView = new ReactRootView(this);
        mReactInstanceManager = com.braincarya.react.android.ReactInstanceManager.builder()
                .setExtras(extras)
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        mReactRootView.startReactApplication(mReactInstanceManager, "HelloWorld", null);

        setContentView(mReactRootView);
    }

    @Override
    public void invokeDefaultOnBackPressed() {
        super.onBackPressed();
    }
    
    //TODO initialize all methods
}

react-native-android-extras's People

Contributors

albertaleksieiev avatar betkapolymorphic avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-android-extras's Issues

Example implementation

Is there some more documentation for this or an example of it in action? I think that would be really helpful for me, because right now I am having some trouble implementing it.

Thank you so much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.