mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Introduce SampleLegacyModule example in RNTester (#38539)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38539 We will use this example to: - Showcase legacy module support in the TurboModule system in RNTester - E2E test legacy module support in the TurboModule system Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D47529295 fbshipit-source-id: b98e315741bed7740c36997d706f48e375b0c815
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a384e076e0
commit
145659241a
@@ -18,6 +18,7 @@ import {
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
Platform,
|
||||
} from 'react-native';
|
||||
|
||||
import styles from './TurboModuleExampleCommon';
|
||||
@@ -58,57 +59,97 @@ class SampleLegacyModuleExample extends React.Component<{||}, State> {
|
||||
|
||||
// Add calls to methods in TurboModule here
|
||||
// $FlowFixMe[missing-local-annot]
|
||||
_tests = {
|
||||
voidFunc: () => getSampleLegacyModule()?.voidFunc(),
|
||||
getBool: () => getSampleLegacyModule()?.getBool(true),
|
||||
getEnum: () => getSampleLegacyModule()?.getEnum(1.0),
|
||||
getNumber: () => getSampleLegacyModule()?.getNumber(99.95),
|
||||
getFloat: () => getSampleLegacyModule()?.getNumber(99.95),
|
||||
getInt: () => getSampleLegacyModule()?.getInt(99),
|
||||
getLongLong: () => getSampleLegacyModule()?.getLongLong(99),
|
||||
getUnsignedLongLong: () => getSampleLegacyModule()?.getUnsignedLongLong(99),
|
||||
getNSInteger: () => getSampleLegacyModule()?.getNSInteger(99),
|
||||
getNSUInteger: () => getSampleLegacyModule()?.getNSUInteger(99),
|
||||
getArray: () =>
|
||||
getSampleLegacyModule()?.getArray([
|
||||
{a: 1, b: 'foo'},
|
||||
{a: 2, b: 'bar'},
|
||||
null,
|
||||
]),
|
||||
getObject: () =>
|
||||
getSampleLegacyModule()?.getObject({a: 1, b: 'foo', c: null}),
|
||||
getString: () => getSampleLegacyModule()?.getString('Hello'),
|
||||
getNullString: () => getSampleLegacyModule()?.getString(null),
|
||||
getNSNumber: () => getSampleLegacyModule()?.getNSNumber(20.0),
|
||||
getUnsafeObject: () =>
|
||||
getSampleLegacyModule()?.getObject({a: 1, b: 'foo', c: null}),
|
||||
getRootTag: () => getSampleLegacyModule()?.getRootTag(this.context),
|
||||
getValue: () =>
|
||||
getSampleLegacyModule()?.getValue(5, 'test', {a: 1, b: 'foo'}),
|
||||
callback: () =>
|
||||
getSampleLegacyModule()?.getValueWithCallback(callbackValue =>
|
||||
this._setResult('callback', callbackValue),
|
||||
),
|
||||
promise: () =>
|
||||
getSampleLegacyModule()
|
||||
?.getValueWithPromise(false)
|
||||
.then(valuePromise => this._setResult('promise', valuePromise)),
|
||||
rejectPromise: () =>
|
||||
getSampleLegacyModule()
|
||||
?.getValueWithPromise(true)
|
||||
.then(() => {})
|
||||
.catch(e => this._setResult('rejectPromise', e.message)),
|
||||
// voidFuncThrows: () => getSampleLegacyModule()?.voidFuncThrows(),
|
||||
// getObjectThrows: () => getSampleLegacyModule()?.getObjectThrows({}),
|
||||
// promiseThrows: () => getSampleLegacyModule()?.promiseThrows(true),
|
||||
// voidFuncAssert: () => getSampleLegacyModule()?.voidFuncAssert(),
|
||||
// getObjectAssert: () => getSampleLegacyModule()?.getObjectAssert({}),
|
||||
// promiseAssert: () => getSampleLegacyModule()?.promiseAssert(true),
|
||||
getConstants: () => getSampleLegacyModule()?.getConstants(),
|
||||
getConst1: () => getSampleLegacyModule()?.const1,
|
||||
getConst2: () => getSampleLegacyModule()?.const2,
|
||||
getConst3: () => getSampleLegacyModule()?.const3,
|
||||
};
|
||||
_tests =
|
||||
Platform.OS === 'ios'
|
||||
? {
|
||||
voidFunc: () => getSampleLegacyModule()?.voidFunc(),
|
||||
getBool: () => getSampleLegacyModule()?.getBool(true),
|
||||
getEnum: () => getSampleLegacyModule()?.getEnum(1.0),
|
||||
getNumber: () => getSampleLegacyModule()?.getNumber(99.95),
|
||||
getFloat: () => getSampleLegacyModule()?.getNumber(99.95),
|
||||
getInt: () => getSampleLegacyModule()?.getInt(99),
|
||||
getLongLong: () => getSampleLegacyModule()?.getLongLong(99),
|
||||
getUnsignedLongLong: () =>
|
||||
getSampleLegacyModule()?.getUnsignedLongLong(99),
|
||||
getNSInteger: () => getSampleLegacyModule()?.getNSInteger(99),
|
||||
getNSUInteger: () => getSampleLegacyModule()?.getNSUInteger(99),
|
||||
getArray: () =>
|
||||
getSampleLegacyModule()?.getArray([
|
||||
{a: 1, b: 'foo'},
|
||||
{a: 2, b: 'bar'},
|
||||
null,
|
||||
]),
|
||||
getObject: () =>
|
||||
getSampleLegacyModule()?.getObject({a: 1, b: 'foo', c: null}),
|
||||
getString: () => getSampleLegacyModule()?.getString('Hello'),
|
||||
getNullString: () => getSampleLegacyModule()?.getString(null),
|
||||
getNSNumber: () => getSampleLegacyModule()?.getNSNumber(20.0),
|
||||
getUnsafeObject: () =>
|
||||
getSampleLegacyModule()?.getObject({a: 1, b: 'foo', c: null}),
|
||||
getRootTag: () => getSampleLegacyModule()?.getRootTag(this.context),
|
||||
getValue: () =>
|
||||
getSampleLegacyModule()?.getValue(5, 'test', {a: 1, b: 'foo'}),
|
||||
callback: () =>
|
||||
getSampleLegacyModule()?.getValueWithCallback(callbackValue =>
|
||||
this._setResult('callback', callbackValue),
|
||||
),
|
||||
promise: () =>
|
||||
getSampleLegacyModule()
|
||||
?.getValueWithPromise(false)
|
||||
.then(valuePromise => this._setResult('promise', valuePromise)),
|
||||
rejectPromise: () =>
|
||||
getSampleLegacyModule()
|
||||
?.getValueWithPromise(true)
|
||||
.then(() => {})
|
||||
.catch(e => this._setResult('rejectPromise', e.message)),
|
||||
getConstants: () => getSampleLegacyModule()?.getConstants(),
|
||||
getConst1: () => getSampleLegacyModule()?.const1,
|
||||
getConst2: () => getSampleLegacyModule()?.const2,
|
||||
getConst3: () => getSampleLegacyModule()?.const3,
|
||||
}
|
||||
: {
|
||||
voidFunc: () => getSampleLegacyModule()?.voidFunc(),
|
||||
getBool: () => getSampleLegacyModule()?.getBool(true),
|
||||
getEnum: () => getSampleLegacyModule()?.getEnum(1.0),
|
||||
getDouble: () => getSampleLegacyModule()?.getDouble(99.95),
|
||||
getInt: () => getSampleLegacyModule()?.getInt(99),
|
||||
getFloat: () => getSampleLegacyModule()?.getFloat(99.95),
|
||||
getObjectDouble: () =>
|
||||
getSampleLegacyModule()?.getObjectDouble(99.95),
|
||||
getObjectInteger: () => getSampleLegacyModule()?.getObjectInteger(99),
|
||||
getObjectFloat: () => getSampleLegacyModule()?.getObjectFloat(99.95),
|
||||
getString: () => getSampleLegacyModule()?.getString('Hello'),
|
||||
getRootTag: () => getSampleLegacyModule()?.getRootTag(this.context),
|
||||
getObject: () =>
|
||||
getSampleLegacyModule()?.getObject({a: 1, b: 'foo', c: null}),
|
||||
getUnsafeObject: () =>
|
||||
getSampleLegacyModule()?.getObject({a: 1, b: 'foo', c: null}),
|
||||
getValue: () =>
|
||||
getSampleLegacyModule()?.getValue(5, 'test', {a: 1, b: 'foo'}),
|
||||
callback: () =>
|
||||
getSampleLegacyModule()?.getValueWithCallback(callbackValue =>
|
||||
this._setResult('callback', callbackValue),
|
||||
),
|
||||
getArray: () =>
|
||||
getSampleLegacyModule()?.getArray([
|
||||
{a: 1, b: 'foo'},
|
||||
{a: 2, b: 'bar'},
|
||||
null,
|
||||
]),
|
||||
promise: () =>
|
||||
getSampleLegacyModule()
|
||||
?.getValueWithPromise(false)
|
||||
.then(valuePromise => this._setResult('promise', valuePromise)),
|
||||
rejectPromise: () =>
|
||||
getSampleLegacyModule()
|
||||
?.getValueWithPromise(true)
|
||||
.then(() => {})
|
||||
.catch(e => this._setResult('rejectPromise', e.message)),
|
||||
getConstants: () => getSampleLegacyModule()?.getConstants(),
|
||||
getConst1: () => getSampleLegacyModule()?.const1,
|
||||
getConst2: () => getSampleLegacyModule()?.const2,
|
||||
getConst3: () => getSampleLegacyModule()?.const3,
|
||||
};
|
||||
|
||||
_setResult(name: string, result: mixed) {
|
||||
this.setState(({testResults}) => ({
|
||||
|
||||
Reference in New Issue
Block a user