Skip to content

Commit 0abd5d6

Browse files
cortinicofacebook-github-bot
authored andcommitted
Back out "Migrate ReactActivity" (#50998)
Summary: Pull Request resolved: #50998 I'm reverting this as this change is too disruptive for the OSS ecosystem. It will break ALL the apps written in Kotlin and it's coming too close to the branch cut which is in less than one week. We need to re-do this migration in a non breaking manner after the branch cut as this is highly disruptive for little benefit at this point Changelog [Android][Changed] - Back out "[RN][Kotlin] Migrate ReactActivity" Original commit changeset: 936263100ca9 Original Phabricator Diff: D73507044 Reviewed By: mdvacca Differential Revision: D73864144 fbshipit-source-id: 264921b1f1cd38301e66364de4b619807272bd27
1 parent 79d3cb7 commit 0abd5d6

File tree

6 files changed

+169
-145
lines changed

6 files changed

+169
-145
lines changed

packages/helloworld/android/app/src/main/java/com/helloworld/MainActivity.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class MainActivity : ReactActivity() {
1818
* Returns the name of the main component registered from JavaScript. This is used to schedule
1919
* rendering of the component.
2020
*/
21-
override val mainComponentName: String?
22-
get() = "HelloWorld"
21+
override fun getMainComponentName(): String = "HelloWorld"
2322

2423
/**
2524
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react;
9+
10+
import android.content.Intent;
11+
import android.content.res.Configuration;
12+
import android.os.Bundle;
13+
import android.view.KeyEvent;
14+
import androidx.annotation.Nullable;
15+
import androidx.appcompat.app.AppCompatActivity;
16+
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
17+
import com.facebook.react.modules.core.PermissionAwareActivity;
18+
import com.facebook.react.modules.core.PermissionListener;
19+
import org.jetbrains.annotations.NotNull;
20+
21+
/** Base Activity for React Native applications. */
22+
public abstract class ReactActivity extends AppCompatActivity
23+
implements DefaultHardwareBackBtnHandler, PermissionAwareActivity {
24+
25+
private final ReactActivityDelegate mDelegate;
26+
27+
protected ReactActivity() {
28+
mDelegate = createReactActivityDelegate();
29+
}
30+
31+
/**
32+
* Returns the name of the main component registered from JavaScript. This is used to schedule
33+
* rendering of the component. e.g. "MoviesApp"
34+
*/
35+
protected @Nullable String getMainComponentName() {
36+
return null;
37+
}
38+
39+
/** Called at construction time, override if you have a custom delegate implementation. */
40+
protected ReactActivityDelegate createReactActivityDelegate() {
41+
return new ReactActivityDelegate(this, getMainComponentName());
42+
}
43+
44+
@Override
45+
protected void onCreate(Bundle savedInstanceState) {
46+
super.onCreate(savedInstanceState);
47+
mDelegate.onCreate(savedInstanceState);
48+
}
49+
50+
@Override
51+
protected void onPause() {
52+
super.onPause();
53+
mDelegate.onPause();
54+
}
55+
56+
@Override
57+
protected void onResume() {
58+
super.onResume();
59+
mDelegate.onResume();
60+
}
61+
62+
@Override
63+
protected void onDestroy() {
64+
super.onDestroy();
65+
mDelegate.onDestroy();
66+
}
67+
68+
public @Nullable ReactDelegate getReactDelegate() {
69+
return mDelegate.getReactDelegate();
70+
}
71+
72+
public ReactActivityDelegate getReactActivityDelegate() {
73+
return mDelegate;
74+
}
75+
76+
@Override
77+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
78+
super.onActivityResult(requestCode, resultCode, data);
79+
mDelegate.onActivityResult(requestCode, resultCode, data);
80+
}
81+
82+
@Override
83+
public boolean onKeyDown(int keyCode, KeyEvent event) {
84+
return mDelegate.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
85+
}
86+
87+
@Override
88+
public boolean onKeyUp(int keyCode, KeyEvent event) {
89+
return mDelegate.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event);
90+
}
91+
92+
@Override
93+
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
94+
return mDelegate.onKeyLongPress(keyCode, event) || super.onKeyLongPress(keyCode, event);
95+
}
96+
97+
@Override
98+
public void onBackPressed() {
99+
if (!mDelegate.onBackPressed()) {
100+
super.onBackPressed();
101+
}
102+
}
103+
104+
@Override
105+
public void invokeDefaultOnBackPressed() {
106+
super.onBackPressed();
107+
}
108+
109+
@Override
110+
public void onNewIntent(Intent intent) {
111+
if (!mDelegate.onNewIntent(intent)) {
112+
super.onNewIntent(intent);
113+
}
114+
}
115+
116+
@Override
117+
public void onUserLeaveHint() {
118+
super.onUserLeaveHint();
119+
mDelegate.onUserLeaveHint();
120+
}
121+
122+
@Override
123+
public void requestPermissions(
124+
String[] permissions, int requestCode, PermissionListener listener) {
125+
mDelegate.requestPermissions(permissions, requestCode, listener);
126+
}
127+
128+
@Override
129+
public void onRequestPermissionsResult(
130+
int requestCode, @NotNull String[] permissions, @NotNull int[] grantResults) {
131+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
132+
mDelegate.onRequestPermissionsResult(requestCode, permissions, grantResults);
133+
}
134+
135+
@Override
136+
public void onWindowFocusChanged(boolean hasFocus) {
137+
super.onWindowFocusChanged(hasFocus);
138+
mDelegate.onWindowFocusChanged(hasFocus);
139+
}
140+
141+
@Override
142+
public void onConfigurationChanged(@NotNull Configuration newConfig) {
143+
super.onConfigurationChanged(newConfig);
144+
mDelegate.onConfigurationChanged(newConfig);
145+
}
146+
147+
protected final ReactNativeHost getReactNativeHost() {
148+
return mDelegate.getReactNativeHost();
149+
}
150+
151+
protected ReactHost getReactHost() {
152+
return mDelegate.getReactHost();
153+
}
154+
155+
protected final ReactInstanceManager getReactInstanceManager() {
156+
return mDelegate.getReactInstanceManager();
157+
}
158+
159+
protected final void loadApp(String appKey) {
160+
mDelegate.loadApp(appKey);
161+
}
162+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.kt

Lines changed: 0 additions & 136 deletions
This file was deleted.

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public ReactInstanceManager getReactInstanceManager() {
110110
return mReactDelegate.getReactInstanceManager();
111111
}
112112

113-
public @Nullable String getMainComponentName() {
113+
public String getMainComponentName() {
114114
return mMainComponentName;
115115
}
116116

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactActivityDelegate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import com.facebook.react.ReactActivityDelegate
2121
*/
2222
public open class DefaultReactActivityDelegate(
2323
activity: ReactActivity,
24-
mainComponentName: String?,
24+
mainComponentName: String,
2525
private val fabricEnabled: Boolean = false,
2626
) : ReactActivityDelegate(activity, mainComponentName) {
2727

packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.io.FileDescriptor
2222
import java.io.PrintWriter
2323

2424
internal class RNTesterActivity : ReactActivity() {
25-
class RNTesterActivityDelegate(val activity: ReactActivity, mainComponentName: String?) :
25+
class RNTesterActivityDelegate(val activity: ReactActivity, mainComponentName: String) :
2626
DefaultReactActivityDelegate(activity, mainComponentName, fabricEnabled) {
2727
private val PARAM_ROUTE = "route"
2828
private lateinit var initialProps: Bundle
@@ -43,9 +43,6 @@ internal class RNTesterActivity : ReactActivity() {
4343
if (this::initialProps.isInitialized) initialProps else Bundle()
4444
}
4545

46-
override val mainComponentName: String?
47-
get() = "RNTesterApp"
48-
4946
override fun onCreate(savedInstanceState: Bundle?) {
5047
super.onCreate(savedInstanceState)
5148

@@ -55,7 +52,7 @@ internal class RNTesterActivity : ReactActivity() {
5552
this.window?.setBackgroundDrawable(ColorDrawable(Color.BLACK))
5653
// register insets listener to update margins on the ReactRootView to avoid overlap w/ system
5754
// bars
58-
reactDelegate?.getReactRootView()?.let { rootView ->
55+
getReactDelegate()?.getReactRootView()?.let { rootView ->
5956
val insetsType: Int =
6057
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
6158

@@ -74,6 +71,8 @@ internal class RNTesterActivity : ReactActivity() {
7471

7572
override fun createReactActivityDelegate() = RNTesterActivityDelegate(this, mainComponentName)
7673

74+
override fun getMainComponentName() = "RNTesterApp"
75+
7776
override fun dump(
7877
prefix: String,
7978
fd: FileDescriptor?,

0 commit comments

Comments
 (0)