Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
> make sure you follow our [migration guide](https://docs.sentry.io/platforms/react-native/migration/) first.
<!-- prettier-ignore-end -->

## Unreleased

### Features

- Create the Android view managers of the SDK on demand, so React Native 0.89+ with the New Architecture does not build their view configs at startup ([#7049](https://github.com/getsentry/sentry-react-native/pull/7049))

## 8.36.0

### Fixes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.sentry.react

import com.facebook.react.bridge.ReactApplicationContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.mockito.kotlin.mock

@RunWith(JUnit4::class)
class RNSentryPackageTest {
private val reactContext: ReactApplicationContext = mock()
private val sentryPackage = RNSentryPackage()

@Test
fun `getViewManagerNames matches the eagerly created view managers`() {
val eagerNames = sentryPackage.createViewManagers(reactContext).map { it.name }.toSet()

assertEquals(eagerNames, sentryPackage.getViewManagerNames(reactContext).toSet())
}

@Test
fun `createViewManager creates the view manager with the requested name`() {
for (name in sentryPackage.getViewManagerNames(reactContext)) {
val viewManager = sentryPackage.createViewManager(reactContext, name)

assertNotNull("No view manager for $name", viewManager)
assertEquals(name, viewManager?.name)
}
}

@Test
fun `createViewManager returns null for an unknown name`() {
assertNull(sentryPackage.createViewManager(reactContext, "UnknownViewManager"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.react.TurboReactPackage;
import com.facebook.react.ViewManagerOnDemandReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfo;
Expand All @@ -16,7 +17,7 @@
import java.util.List;
import java.util.Map;

public class RNSentryPackage extends TurboReactPackage {
public class RNSentryPackage extends TurboReactPackage implements ViewManagerOnDemandReactPackage {

private static final boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;

Expand Down Expand Up @@ -99,4 +100,29 @@ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext
new RNSentryReplayMaskManager(),
new RNSentryReplayUnmaskManager());
}

@NonNull
@Override
public List<String> getViewManagerNames(@NonNull ReactApplicationContext reactContext) {
return List.of(
RNSentryOnDrawReporterManager.REACT_CLASS,
RNSentryReplayMaskManagerImpl.REACT_CLASS,
RNSentryReplayUnmaskManagerImpl.REACT_CLASS);
}

@Nullable
@Override
public ViewManager createViewManager(
@NonNull ReactApplicationContext reactContext, @NonNull String viewManagerName) {
switch (viewManagerName) {
case RNSentryOnDrawReporterManager.REACT_CLASS:
return new RNSentryOnDrawReporterManager(reactContext);
case RNSentryReplayMaskManagerImpl.REACT_CLASS:
return new RNSentryReplayMaskManager();
case RNSentryReplayUnmaskManagerImpl.REACT_CLASS:
return new RNSentryReplayUnmaskManager();
default:
return null;
}
}
}
Loading