Skip to content

Commit

Permalink
Migrate ScreenshotManager from NativeModule to TurboModule
Browse files Browse the repository at this point in the history
Summary:
Changelog: [JS] Migrate ScreenshotManager from NativeModule to TurboModule. Fix SnapshotExample in rn-tester.

`const ScreenshotManager = NativeModules.ScreenshotManager;` makes all of RNTesterAppRoute render blank in Bridgeless, because we throw a jsi::JSError when JS calls `NativeModule.get` while in Bridgeless.

Reviewed By: RSNara

Differential Revision: D33640935

fbshipit-source-id: 124a3b43e1440a7ca0071c95c4388350d2e4affa
  • Loading branch information
p-sun authored and facebook-github-bot committed Jan 19, 2022
1 parent 9d2df5b commit b13e41d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
16 changes: 12 additions & 4 deletions packages/rn-tester/NativeModuleExample/NativeScreenshotManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@

import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
import type {UnsafeObject} from 'react-native/Libraries/Types/CodegenTypes';

export type ScreenshotManagerOptions = UnsafeObject;

export interface Spec extends TurboModule {
+getConstants: () => {||};
takeSnapshot(id: string): Promise<string>;
takeScreenshot(
id: string,
options: ScreenshotManagerOptions,
): Promise<string>;
}

const NativeModule = TurboModuleRegistry.get<Spec>('ScreenshotManager');

export function takeSnapshot(id: string): Promise<string> {
export function takeScreenshot(
id: string,
options: ScreenshotManagerOptions,
): Promise<string> {
if (NativeModule != null) {
return NativeModule.takeSnapshot(id);
return NativeModule.takeScreenshot(id, options);
}
return Promise.reject();
}
8 changes: 4 additions & 4 deletions packages/rn-tester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ SPEC CHECKSUMS:
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
FBLazyVector: b81a2b70c72d8b0aefb652cea22c11e9ffd02949
FBReactNativeSpec: 3f88f49873cc4123da7877f1b183e7776bbc4fa9
FBReactNativeSpec: 35cca37e6328d64b4e38c4adb1a28db74b60aeac
Flipper: 30e8eeeed6abdc98edaf32af0cda2f198be4b733
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
Flipper-DoubleConversion: 57ffbe81ef95306cc9e69c4aa3aeeeeb58a6a28c
Expand All @@ -892,7 +892,7 @@ SPEC CHECKSUMS:
Flipper-RSocket: d9d9ade67cbecf6ac10730304bf5607266dd2541
FlipperKit: d8d346844eca5d9120c17d441a2f38596e8ed2b9
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: c10b67b343303f51715e5c5eedb18a41402f350a
glog: 476ee3e89abb49e07f822b48323c51c57124b572
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b
RCT-Folly: 803a9cfd78114b2ec0f140cfa6fa2a6bafb2d685
Expand Down Expand Up @@ -923,10 +923,10 @@ SPEC CHECKSUMS:
React-RCTTest: 12bbd7fc2e72bd9920dc7286c5b8ef96639582b6
React-RCTText: e9146b2c0550a83d1335bfe2553760070a2d75c7
React-RCTVibration: 50be9c390f2da76045ef0dfdefa18b9cf9f35cfa
React-rncore: c76a90ccef0be9fc0f6dab7c16d9194ec6b54e13
React-rncore: d292b6c2196dcd555622a538e1b206aa2e0ad8a2
React-runtimeexecutor: 4b0c6eb341c7d3ceb5e2385cb0fdb9bf701024f3
ReactCommon: 7a2714d1128f965392b6f99a8b390e3aa38c9569
ScreenshotManager: bae0da23de347c4527710cca486f6b156902512b
ScreenshotManager: e8da2e62b3c08a87cece436776ce91555ecec77c
Yoga: c0d06f5380d34e939f55420669a60fe08b79bd75
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ const {
Text,
View,
Alert,
NativeModules,
findNodeHandle,
} = require('react-native');
const ScreenshotManager = NativeModules.ScreenshotManager;
const ScreenshotManager = require('../../../NativeModuleExample/NativeScreenshotManager');

const BUTTONS = ['Option 0', 'Option 1', 'Option 2', 'Delete', 'Cancel'];
const DESTRUCTIVE_INDEX = 3;
Expand Down
11 changes: 2 additions & 9 deletions packages/rn-tester/js/examples/Snapshot/SnapshotExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@
'use strict';

const React = require('react');
const {
Alert,
Image,
NativeModules,
StyleSheet,
Text,
View,
} = require('react-native');
const ScreenshotManager = NativeModules.ScreenshotManager;
const {Alert, Image, StyleSheet, Text, View} = require('react-native');
const ScreenshotManager = require('../../../NativeModuleExample/NativeScreenshotManager');

class ScreenshotExample extends React.Component<{...}, $FlowFixMeState> {
state = {
Expand Down

0 comments on commit b13e41d

Please sign in to comment.