Skip to content

Commit

Permalink
et update-rn
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldonadel committed Aug 22, 2024
1 parent 047fcd8 commit 04eeb55
Show file tree
Hide file tree
Showing 14 changed files with 3,026 additions and 3,606 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins {
alias(libs.plugins.kotlin.android)
}

version = project.findProperty("VERSION_NAME")?.toString()!!
version = "52.0.0"

group = "com.facebook.react"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 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;

import androidx.annotation.NonNull;
Expand All @@ -29,24 +28,23 @@
/** Abstract class that supports lazy loading of NativeModules by default. */
public abstract class BaseReactPackage implements ReactPackage {

@Override
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
throw new UnsupportedOperationException(
"createNativeModules method is not supported. Use getModule() method instead.");
}
@Override
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
throw new UnsupportedOperationException("createNativeModules method is not supported. Use getModule() method instead.");
}

/**
/**
* The API needed for TurboModules. Given a module name, it returns an instance of {@link
* NativeModule} for the name
*
* @param name name of the Native Module
* @param reactContext {@link ReactApplicationContext} context for this
*/
@Override
public abstract @Nullable NativeModule getModule(
@NonNull String name, @NonNull ReactApplicationContext reactContext);
@Override
@Nullable
public abstract NativeModule getModule(@NonNull String name, @NonNull ReactApplicationContext reactContext);

/**
/**
* This is a temporary method till we implement TurboModules. Once we implement TurboModules, we
* will be able to directly call {@link BaseReactPackage#getModule(String,
* ReactApplicationContext)} This method will be removed when TurboModule implementation is
Expand All @@ -55,105 +53,99 @@ public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext r
* @param reactContext
* @return
*/
/** package */
Iterable<ModuleHolder> getNativeModuleIterator(final ReactApplicationContext reactContext) {
final Set<Map.Entry<String, ReactModuleInfo>> entrySet =
getReactModuleInfoProvider().getReactModuleInfos().entrySet();
final Iterator<Map.Entry<String, ReactModuleInfo>> entrySetIterator = entrySet.iterator();
// This should ideally be an IteratorConvertor, but we don't have any internal library for it
return () ->
new Iterator<ModuleHolder>() {
@Nullable Map.Entry<String, ReactModuleInfo> nextEntry = null;

private void findNext() {
while (entrySetIterator.hasNext()) {
Map.Entry<String, ReactModuleInfo> entry = entrySetIterator.next();
ReactModuleInfo reactModuleInfo = entry.getValue();

// This Iterator is used to create the NativeModule registry. The NativeModule
// registry must not have TurboModules. Therefore, if TurboModules are enabled, and
// the current NativeModule is a TurboModule, we need to skip iterating over it.
if (ReactFeatureFlags.useTurboModules && reactModuleInfo.isTurboModule()) {
continue;
}

nextEntry = entry;
return;
/** package */
public Iterable<ModuleHolder> getNativeModuleIterator(final ReactApplicationContext reactContext) {
final Set<Map.Entry<String, ReactModuleInfo>> entrySet = getReactModuleInfoProvider().getReactModuleInfos().entrySet();
final Iterator<Map.Entry<String, ReactModuleInfo>> entrySetIterator = entrySet.iterator();
// This should ideally be an IteratorConvertor, but we don't have any internal library for it
return () -> new Iterator<ModuleHolder>() {

@Nullable
public Map.Entry<String, ReactModuleInfo> nextEntry = null;

private void findNext() {
while (entrySetIterator.hasNext()) {
Map.Entry<String, ReactModuleInfo> entry = entrySetIterator.next();
ReactModuleInfo reactModuleInfo = entry.getValue();
// the current NativeModule is a TurboModule, we need to skip iterating over it.
if (ReactFeatureFlags.useTurboModules && reactModuleInfo.isTurboModule()) {
continue;
}
nextEntry = entry;
return;
}
nextEntry = null;
}
nextEntry = null;
}

@Override
public boolean hasNext() {
if (nextEntry == null) {
findNext();
@Override
public boolean hasNext() {
if (nextEntry == null) {
findNext();
}
return nextEntry != null;
}
return nextEntry != null;
}

@Override
public ModuleHolder next() {
if (nextEntry == null) {
findNext();
@Override
public ModuleHolder next() {
if (nextEntry == null) {
findNext();
}
if (nextEntry == null) {
throw new NoSuchElementException("ModuleHolder not found");
}
Map.Entry<String, ReactModuleInfo> entry = nextEntry;
// Advance iterator
findNext();
String name = entry.getKey();
ReactModuleInfo reactModuleInfo = entry.getValue();
return new ModuleHolder(reactModuleInfo, new ModuleHolderProvider(name, reactContext));
}

if (nextEntry == null) {
throw new NoSuchElementException("ModuleHolder not found");
@Override
public void remove() {
throw new UnsupportedOperationException("Cannot remove native modules from the list");
}

Map.Entry<String, ReactModuleInfo> entry = nextEntry;

// Advance iterator
findNext();
String name = entry.getKey();
ReactModuleInfo reactModuleInfo = entry.getValue();
return new ModuleHolder(reactModuleInfo, new ModuleHolderProvider(name, reactContext));
}

@Override
public void remove() {
throw new UnsupportedOperationException("Cannot remove native modules from the list");
}
};
}
}

/**
/**
* @param reactContext react application context that can be used to create View Managers.
* @return list of module specs that can create the View Managers.
*/
protected List<ModuleSpec> getViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
List<ModuleSpec> viewManagerModuleSpecs = getViewManagers(reactContext);
if (viewManagerModuleSpecs == null || viewManagerModuleSpecs.isEmpty()) {
return Collections.emptyList();
protected List<ModuleSpec> getViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

List<ViewManager> viewManagers = new ArrayList<>();
for (ModuleSpec moduleSpec : viewManagerModuleSpecs) {
viewManagers.add((ViewManager) moduleSpec.getProvider().get());
@Override
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
List<ModuleSpec> viewManagerModuleSpecs = getViewManagers(reactContext);
if (viewManagerModuleSpecs == null || viewManagerModuleSpecs.isEmpty()) {
return Collections.emptyList();
}
List<ViewManager> viewManagers = new ArrayList<>();
for (ModuleSpec moduleSpec : viewManagerModuleSpecs) {
viewManagers.add((ViewManager) moduleSpec.getProvider().get());
}
return viewManagers;
}
return viewManagers;
}

public abstract ReactModuleInfoProvider getReactModuleInfoProvider();
public abstract ReactModuleInfoProvider getReactModuleInfoProvider();

private class ModuleHolderProvider implements Provider<NativeModule> {
private class ModuleHolderProvider implements Provider<NativeModule> {

private final String mName;
private final ReactApplicationContext mReactContext;
public final String mName;

public ModuleHolderProvider(String name, ReactApplicationContext reactContext) {
mName = name;
mReactContext = reactContext;
}
public final ReactApplicationContext mReactContext;

@Override
public @Nullable NativeModule get() {
return getModule(mName, mReactContext);
public ModuleHolderProvider(String name, ReactApplicationContext reactContext) {
mName = name;
mReactContext = reactContext;
}

@Override
@Nullable
public NativeModule get() {
return getModule(mName, mReactContext);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@
* 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.bridge;

/** Crashy crashy exception handler. */
public class DefaultJSExceptionHandler implements JSExceptionHandler {

@Override
public void handleException(Exception e) {
if (e instanceof RuntimeException) {
// Because we are rethrowing the original exception, the original stacktrace will be
// preserved.
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
@Override
public void handleException(Exception e) {
try {
{
if (e instanceof RuntimeException) {
// preserved.
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
}
} catch (RuntimeException expoException) {
try {
Class.forName("host.exp.exponent.ReactNativeStaticHelpers").getMethod("handleReactNativeError", String.class, Object.class, Integer.class, Boolean.class).invoke(null, expoException.getMessage(), null, -1, true);
} catch (Exception expoHandleErrorException) {
expoHandleErrorException.printStackTrace();
}
}
}
}
}
Loading

0 comments on commit 04eeb55

Please sign in to comment.