Skip to content

Commit

Permalink
quick fixes to enable compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
vonovak committed Feb 23, 2025
1 parent ce3ff81 commit 746bb21
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* APIs for asynchronously loading the JS bundle.
*/
@Nullsafe(Nullsafe.Mode.LOCAL)
class BridgelessDevSupportManager extends DevSupportManagerBase {
public class BridgelessDevSupportManager extends DevSupportManagerBase {

public BridgelessDevSupportManager(
Context context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.facebook.react.packagerconnection.PackagerConnectionSettings
* [com.facebook.react.devsupport]. For accessing some of the settings by external modules this
* class implements an external interface [DeveloperSettings].
*/
internal class DevInternalSettings(applicationContext: Context, private val listener: Listener?) :
public class DevInternalSettings(applicationContext: Context, private val listener: Listener?) :
DeveloperSettings, OnSharedPreferenceChangeListener {
private val preferences: SharedPreferences =
PreferenceManager.getDefaultSharedPreferences(applicationContext)
Expand Down Expand Up @@ -86,19 +86,19 @@ internal class DevInternalSettings(applicationContext: Context, private val list
override var isStartSamplingProfilerOnInit: Boolean = false

// Not supported.
override fun addMenuItem(title: String) = Unit
override fun addMenuItem(title: String): Unit = Unit

override var isHotModuleReplacementEnabled: Boolean
get() = preferences.getBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, true)
set(enabled) {
preferences.edit().putBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, enabled).apply()
}

interface Listener {
fun onInternalSettingsChanged()
public interface Listener {
public fun onInternalSettingsChanged()
}

companion object {
public companion object {
private const val PREFS_FPS_DEBUG_KEY = "fps_debug"
private const val PREFS_JS_DEV_MODE_DEBUG_KEY = "js_dev_mode_debug"
private const val PREFS_JS_MINIFY_DEBUG_KEY = "js_minify_debug"
Expand All @@ -107,4 +107,14 @@ internal class DevInternalSettings(applicationContext: Context, private val list
private const val PREFS_HOT_MODULE_REPLACEMENT_KEY = "hot_module_replacement"
private const val PREFS_REMOTE_JS_DEBUG_KEY = "remote_js_debug"
}

private var exponentActivityId: Int = -1

public fun setExponentActivityId(value: Int) {
exponentActivityId = value
}

public override fun getExponentActivityId(): Int {
return exponentActivityId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
import com.facebook.react.packagerconnection.RequestHandler;
import com.facebook.react.packagerconnection.Responder;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -94,7 +93,7 @@ public interface CallbackWithBundleLoader {
private final BroadcastReceiver mReloadAppBroadcastReceiver;
private final DevServerHelper mDevServerHelper;
private final LinkedHashMap<String, DevOptionHandler> mCustomDevOptions = new LinkedHashMap<>();
private final ReactInstanceDevHelper mReactInstanceDevHelper;
protected final ReactInstanceDevHelper mReactInstanceDevHelper;
private final @Nullable String mJSAppBundleName;
private final File mJSBundleDownloadedFile;
private final File mJSSplitBundlesDir;
Expand All @@ -107,7 +106,7 @@ public interface CallbackWithBundleLoader {
private @Nullable DebugOverlayController mDebugOverlayController;
private boolean mDevLoadingViewVisible = false;
private int mPendingJSSplitBundleRequests = 0;
private @Nullable ReactContext mCurrentContext;
private @Nullable ReactContext mCurrentReactContext;
private final DeveloperSettings mDevSettings;
private boolean mIsReceiverRegistered = false;
private boolean mIsShakeDetectorStarted = false;
Expand Down Expand Up @@ -279,26 +278,6 @@ public Pair<String, StackFrame[]> processErrorCustomizers(Pair<String, StackFram
return errorInfo;
}

@Override
public void updateJSError(
final String message, final ReadableArray details, final int errorCookie) {
UiThreadUtil.runOnUiThread(
() -> {
// Since we only show the first JS error in a succession of JS errors, make sure we only
// update the error message for that error message. This assumes that updateJSError
// belongs to the most recent showNewJSError
if ((mRedBoxSurfaceDelegate != null && !mRedBoxSurfaceDelegate.isShowing())
|| errorCookie != mLastErrorCookie) {
return;
}

// The RedBox surface delegate will always show the latest error
updateLastErrorInfo(
message, StackTraceHelper.convertJsStackTrace(details), errorCookie, ErrorType.JS);
mRedBoxSurfaceDelegate.show();
});
}

@Override
public void hideRedboxDialog() {
if (mRedBoxSurfaceDelegate == null) {
Expand Down Expand Up @@ -472,14 +451,15 @@ public void onOptionSelected() {
() -> {
boolean nextEnabled = !mDevSettings.isHotModuleReplacementEnabled();
mDevSettings.setHotModuleReplacementEnabled(nextEnabled);
if (mCurrentContext != null) {
if (mCurrentReactContext != null) {
if (nextEnabled) {
mCurrentContext.getJSModule(HMRClient.class).enable();
mCurrentReactContext.getJSModule(HMRClient.class).enable();
} else {
mCurrentContext.getJSModule(HMRClient.class).disable();
mCurrentReactContext.getJSModule(HMRClient.class).disable();
}
}
if (nextEnabled && !mDevSettings.isJSDevModeEnabled()) {
expo_transformer_remove: if (nextEnabled && !mDevSettings.isJSDevModeEnabled()) {
// if (nextEnabled && !mDevSettings.isJSDevModeEnabled()) {
Toast.makeText(
mApplicationContext,
mApplicationContext.getString(R.string.catalyst_hot_reloading_auto_enable),
Expand All @@ -506,7 +486,7 @@ public void onOptionSelected() {
}
mDevSettings.setFpsDebugEnabled(!mDevSettings.isFpsDebugEnabled());
});
options.put(
expo_transformer_remove: options.put(
mApplicationContext.getString(R.string.catalyst_settings),
() -> {
Intent intent = new Intent(mApplicationContext, DevSettingsActivity.class);
Expand Down Expand Up @@ -585,8 +565,10 @@ public View getView(int position, @Nullable View convertView, ViewGroup parent)
.setOnCancelListener(dialog -> mDevOptionsDialog = null)
.create();
mDevOptionsDialog.show();
if (mCurrentContext != null) {
mCurrentContext.getJSModule(RCTNativeAppEventEmitter.class).emit("RCTDevMenuShown", null);
if (mCurrentReactContext != null) {
mCurrentReactContext
.getJSModule(RCTNativeAppEventEmitter.class)
.emit("RCTDevMenuShown", null);
}
}

Expand Down Expand Up @@ -631,11 +613,19 @@ public void onNewReactContextCreated(ReactContext reactContext) {

@Override
public void onReactInstanceDestroyed(ReactContext reactContext) {
if (reactContext == mCurrentContext) {
if (reactContext == mCurrentReactContext) {
// only call reset context when the destroyed context matches the one that is currently set
// for this manager
resetCurrentContext(null);
}

// If some JNI types (e.g. jni::HybridClass) are used in JSI (e.g. jsi::HostObject), they might
// not be immediately deleted on an app refresh as both Java and JavaScript are
// garbage-collected languages and the memory might float around for a while. For C++
// developers, this will be hard to debug as destructors might be called at a later point, so in
// this case we trigger a Java GC to maybe eagerly collect such objects when the app
// reloads.
System.gc();
}

@Override
Expand Down Expand Up @@ -699,12 +689,12 @@ public boolean hasUpToDateJSBundleInCache() {
}

private void resetCurrentContext(@Nullable ReactContext reactContext) {
if (mCurrentContext == reactContext) {
if (mCurrentReactContext == reactContext) {
// new context is the same as the old one - do nothing
return;
}

mCurrentContext = reactContext;
mCurrentReactContext = reactContext;

// Recreate debug overlay controller with new CatalystInstance object
if (mDebugOverlayController != null) {
Expand All @@ -714,15 +704,17 @@ private void resetCurrentContext(@Nullable ReactContext reactContext) {
mDebugOverlayController = new DebugOverlayController(reactContext);
}

if (mCurrentContext != null) {
if (mCurrentReactContext != null) {
try {
URL sourceUrl = new URL(getSourceUrl());
String path = sourceUrl.getPath().substring(1); // strip initial slash in path
String host = sourceUrl.getHost();
String scheme = sourceUrl.getProtocol();
int port = sourceUrl.getPort() != -1 ? sourceUrl.getPort() : sourceUrl.getDefaultPort();
mCurrentContext
mCurrentReactContext
.getJSModule(HMRClient.class)
.setup("android", path, host, port, mDevSettings.isHotModuleReplacementEnabled());
.setup(
"android", path, host, port, mDevSettings.isHotModuleReplacementEnabled(), scheme);
} catch (MalformedURLException e) {
showNewJavaError(e.getMessage(), e);
}
Expand All @@ -740,8 +732,8 @@ public void reloadSettings() {
}
}

protected @Nullable ReactContext getCurrentContext() {
return mCurrentContext;
public @Nullable ReactContext getCurrentReactContext() {
return mCurrentReactContext;
}

public @Nullable String getJSAppBundleName() {
Expand Down Expand Up @@ -818,7 +810,7 @@ public void fetchSplitBundleAndCreateBundleLoader(
public void onSuccess() {
UiThreadUtil.runOnUiThread(() -> hideSplitBundleDevLoadingView());

@Nullable ReactContext context = mCurrentContext;
@Nullable ReactContext context = mCurrentReactContext;
if (context == null || !context.hasActiveReactInstance()) {
return;
}
Expand Down Expand Up @@ -898,29 +890,6 @@ public int getLastErrorCookie() {
return mLastErrorType;
}

private void handleCaptureHeap(final Responder responder) {
if (mCurrentContext == null) {
return;
}
JSCHeapCapture heapCapture = mCurrentContext.getNativeModule(JSCHeapCapture.class);

if (heapCapture != null) {
heapCapture.captureHeap(
mApplicationContext.getCacheDir().getPath(),
new JSCHeapCapture.CaptureCallback() {
@Override
public void onSuccess(File capture) {
responder.respond(capture.toString());
}

@Override
public void onFailure(JSCHeapCapture.CaptureException error) {
responder.error(error.toString());
}
});
}
}

private void updateLastErrorInfo(
@Nullable final String message,
final StackFrame[] stack,
Expand Down Expand Up @@ -1109,11 +1078,6 @@ public void onPackagerDevMenuCommand() {
UiThreadUtil.runOnUiThread(() -> showDevOptionsDialog());
}

@Override
public void onCaptureHeapCommand(final Responder responder) {
UiThreadUtil.runOnUiThread(() -> handleCaptureHeap(responder));
}

@Override
public @Nullable Map<String, RequestHandler> customCommandHandlers() {
return mCustomPackagerCommandHandlers;
Expand Down Expand Up @@ -1195,7 +1159,7 @@ private void compatRegisterReceiver(
@Override
public void openDebugger() {
mDevServerHelper.openDebugger(
mCurrentContext, mApplicationContext.getString(R.string.catalyst_open_debugger_error));
mCurrentReactContext, mApplicationContext.getString(R.string.catalyst_open_debugger_error));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ public interface DeveloperSettings {

/** Add an item to the dev menu. */
public fun addMenuItem(title: String)

public fun getExponentActivityId(): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public interface ResponseHandler {
private static @Nullable com.facebook.react.modules.network.CustomClientBuilder
customClientBuilder = null;

private final OkHttpClient mClient;
public final OkHttpClient mClient;
private final ForwardingCookieHandler mCookieHandler = new ForwardingCookieHandler();
private final @Nullable String mDefaultUserAgent;
private final @Nullable CookieJarContainer mCookieJarContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ import java.util.Locale

public object AndroidInfoHelpers {

public const val EMULATOR_LOCALHOST: String = "10.0.2.2"
public const val GENYMOTION_LOCALHOST: String = "10.0.3.2"
public const val DEVICE_LOCALHOST: String = "localhost"
public const val METRO_HOST_PROP_NAME: String = "metro.host"
public var EMULATOR_LOCALHOST: String? = "10.0.2.2"
public var GENYMOTION_LOCALHOST: String? = "10.0.3.2"
@JvmField
public var DEVICE_LOCALHOST: String? = "localhost"
public val METRO_HOST_PROP_NAME: String = "metro.host"
private val TAG = AndroidInfoHelpers::class.java.simpleName
private var metroHostPropValue: String? = null

// Move the port overrides into companion object
public companion object {
@JvmField
public var sDevServerPortOverride: Int? = null
@JvmField
public var sInspectorProxyPortOverride: Int? = null
}
@JvmField
public var sDevServerPortOverride: Int? = null

@JvmField
public var sInspectorProxyPortOverride: Int? = null

private fun isRunningOnGenymotion(): Boolean = Build.FINGERPRINT.contains("vbox")

Expand Down Expand Up @@ -108,7 +107,7 @@ public object AndroidInfoHelpers {
}

private fun getServerIpAddress(port: Int): String {
val ipAddress: String =
val ipAddress =
when {
getMetroHostPropValue().isNotEmpty() -> getMetroHostPropValue()
isRunningOnGenymotion() -> GENYMOTION_LOCALHOST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ void CatalystInstanceImpl::jniLoadScriptFromFile(
}
}
}

//packages/react-native/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp
void CatalystInstanceImpl::jniLoadScriptFromString(
const std::string& scriptStdString,
const std::string& sourceURL,
bool loadSynchronously) {
std::unique_ptr<const JSBigStdString> script = folly::make_unique<const JSBigStdString>(scriptStdString);
std::unique_ptr<const JSBigStdString> script = std::make_unique<const JSBigStdString>(scriptStdString);
instance_->loadScriptFromString(std::move(script), sourceURL, loadSynchronously);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';

type OrientationChangeEvent = $ReadOnly<{|
orientation: 'portrait' | 'landscape',
orientation: string // 'portrait' | 'landscape',
|}>;

type NativeProps = $ReadOnly<{|
Expand Down

0 comments on commit 746bb21

Please sign in to comment.