mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
migrate RNTesterActivity to Kotlin (#39584)
Summary: PR converts RNTesterActivity to Kotlin as requested in https://github.com/facebook/react-native/issues/38825 . ## Changelog: [INTERNAL] [CHANGED] - Migrate RNTesterActivity to Kotlin Pull Request resolved: https://github.com/facebook/react-native/pull/39584 Test Plan: 1. run `yarn android` 2. Check whether RN Tester runs as expected Reviewed By: cortinico Differential Revision: D49506304 Pulled By: ryancat fbshipit-source-id: 7675b43e6ef1d09f9a6e09e5a70526fc59f07bbf
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2fb4547aa0
commit
0f2ecd3254
-59
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uiapp;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.ReactActivity;
|
||||
import com.facebook.react.ReactActivityDelegate;
|
||||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
|
||||
import com.facebook.react.defaults.DefaultReactActivityDelegate;
|
||||
|
||||
public class RNTesterActivity extends ReactActivity {
|
||||
public static class RNTesterActivityDelegate extends DefaultReactActivityDelegate {
|
||||
private static final String PARAM_ROUTE = "route";
|
||||
private Bundle mInitialProps = null;
|
||||
private final @Nullable ReactActivity mActivity;
|
||||
|
||||
public RNTesterActivityDelegate(ReactActivity activity, String mainComponentName) {
|
||||
super(activity, mainComponentName, DefaultNewArchitectureEntryPoint.getFabricEnabled());
|
||||
this.mActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// Get remote param before calling super which uses it
|
||||
Bundle bundle = mActivity.getIntent().getExtras();
|
||||
if (bundle != null && bundle.containsKey(PARAM_ROUTE)) {
|
||||
String routeUri =
|
||||
new StringBuilder("rntester://example/")
|
||||
.append(bundle.getString(PARAM_ROUTE))
|
||||
.append("Example")
|
||||
.toString();
|
||||
mInitialProps = new Bundle();
|
||||
mInitialProps.putString("exampleFromAppetizeParams", routeUri);
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bundle getLaunchOptions() {
|
||||
return mInitialProps;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReactActivityDelegate createReactActivityDelegate() {
|
||||
return new RNTesterActivityDelegate(this, getMainComponentName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMainComponentName() {
|
||||
return "RNTesterApp";
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uiapp
|
||||
|
||||
import android.os.Bundle
|
||||
import com.facebook.react.ReactActivity
|
||||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
|
||||
import com.facebook.react.defaults.DefaultReactActivityDelegate
|
||||
|
||||
class RNTesterActivity : ReactActivity() {
|
||||
class RNTesterActivityDelegate(val activity: ReactActivity, mainComponentName: String) :
|
||||
DefaultReactActivityDelegate(activity, mainComponentName, fabricEnabled) {
|
||||
private val PARAM_ROUTE = "route"
|
||||
private lateinit var initialProps: Bundle
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
// Get remote param before calling super which uses it
|
||||
val bundle = activity.getIntent()?.getExtras()
|
||||
|
||||
if (bundle != null && bundle.containsKey(PARAM_ROUTE)) {
|
||||
val routeUri = "rntester://example/${bundle.getString(PARAM_ROUTE)}Example"
|
||||
initialProps = Bundle()
|
||||
initialProps?.putString("exampleFromAppetizeParams", routeUri)
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun getLaunchOptions() = initialProps
|
||||
}
|
||||
|
||||
override fun createReactActivityDelegate() = RNTesterActivityDelegate(this, mainComponentName)
|
||||
|
||||
override fun getMainComponentName() = "RNTesterApp"
|
||||
}
|
||||
Reference in New Issue
Block a user