Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

## 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))

### Fixes

- Fix the TypeScript error `Cannot find module 'react-native/Libraries/Types/CodegenTypes'` with React Native 0.88 and `skipLibCheck: false` ([#7061](https://github.com/getsentry/sentry-react-native/pull/7061))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.sentry.react

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test only runs against RN 0.72, since the PR targets RN 0.89+ features, it would be nice to have tests on the newer target too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment here #7067 (comment) to recheck this when the final 0.89.0 is out


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