注册模块mainactivity.java反应原生

时间:2016-03-15 11:05:15

标签: java android react-native main-activity

我试图按照这些说明操作:https://www.npmjs.com/package/react-native-text-input-layout。我对mainactivity.java部分的注册模块感到困惑。我的mainactivity.java看起来并不像说明书那样。

这是我的mainactivity.java:

package com.starterkit;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends ReactActivity {

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */
@Override
protected String getMainComponentName() {
    return "StarterKit";
}

/**
 * Returns whether dev mode should be enabled.
 * This enables e.g. the dev menu.
 */
@Override
protected boolean getUseDeveloperSupport() {
    return BuildConfig.DEBUG;
}

   /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage()
  );
}
}

这是指示中的mainactivity.java:

 import com.memox.rntextinputlayout.RNTextInputLayoutPackage;  // <---       import 

 public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
 ......

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);

mReactInstanceManager = ReactInstanceManager.builder()
  .setApplication(getApplication())
  .setBundleAssetName("index.android.bundle")
  .setJSMainModuleName("index.android")
  .addPackage(new MainReactPackage())
  .addPackage(new RNTextInputLayoutPackage()) // <------ add this line to your MainActivity class 
  .setUseDeveloperSupport(BuildConfig.DEBUG)
  .setInitialLifecycleState(LifecycleState.RESUMED)
  .build();

mReactRootView.startReactApplication(mReactInstanceManager, "AndroidRNSample", null);

setContentView(mReactRootView);
}
......
}

1 个答案:

答案 0 :(得分:1)

您可以这样添加:

protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage()
   ,new RNTextInputLayoutPackage()
  );
}