mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1cb6a5c86 | ||
|
|
7725a0aee3 | ||
|
|
b5329ecd6d | ||
|
|
6892dde363 | ||
|
|
eb61e6f783 | ||
|
|
df6ba3f155 | ||
|
|
5baf1e6d00 |
@@ -4,7 +4,7 @@ inputs:
|
||||
node-version:
|
||||
description: 'The node.js version to use'
|
||||
required: false
|
||||
default: '22'
|
||||
default: '22.14.0'
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
|
||||
@@ -2,6 +2,8 @@ name: yarn-install
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Setup node.js
|
||||
uses: ./.github/actions/setup-node
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -65,15 +65,15 @@ const TestTemplate = ({
|
||||
propValue: string,
|
||||
}) => `
|
||||
TEST(${componentName}_${testName}, etc) {
|
||||
RawPropsParser propParser{};
|
||||
auto propParser = RawPropsParser();
|
||||
propParser.prepare<${componentName}>();
|
||||
${componentName} sourceProps{};
|
||||
RawProps rawProps(folly::dynamic::object("${propName}", ${propValue}));
|
||||
auto const &sourceProps = ${componentName}();
|
||||
auto const &rawProps = RawProps(folly::dynamic::object("${propName}", ${propValue}));
|
||||
|
||||
ContextContainer contextContainer{};
|
||||
PropsParserContext parserContext{-1, contextContainer};
|
||||
|
||||
rawProps.parse(propParser);
|
||||
rawProps.parse(propParser, parserContext);
|
||||
${componentName}(parserContext, sourceProps, rawProps);
|
||||
}
|
||||
`;
|
||||
|
||||
+240
-240
File diff suppressed because it is too large
Load Diff
@@ -242,6 +242,8 @@ function reactConsoleErrorHandler(...args) {
|
||||
if (__DEV__) {
|
||||
// If we're not reporting to the console in reportException,
|
||||
// we need to report it as a console.error here.
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (!reportToConsole) {
|
||||
require('../LogBox/LogBox').default.addConsoleLog('error', ...args);
|
||||
}
|
||||
|
||||
@@ -73,6 +73,8 @@ const InteractionManagerImpl = {
|
||||
* Notify manager that an interaction has started.
|
||||
*/
|
||||
createInteractionHandle(): Handle {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG && console.log('InteractionManager: create interaction handle');
|
||||
_scheduleUpdate();
|
||||
const handle = ++_inc;
|
||||
@@ -84,6 +86,8 @@ const InteractionManagerImpl = {
|
||||
* Notify manager that an interaction has completed.
|
||||
*/
|
||||
clearInteractionHandle(handle: Handle) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG && console.log('InteractionManager: clear interaction handle');
|
||||
invariant(!!handle, 'InteractionManager: Must provide a handle to clear.');
|
||||
_scheduleUpdate();
|
||||
|
||||
@@ -99,9 +99,13 @@ class TaskQueue {
|
||||
const task = queue.shift();
|
||||
try {
|
||||
if (typeof task === 'object' && task.gen) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG && console.log('TaskQueue: genPromise for task ' + task.name);
|
||||
this._genPromise(task);
|
||||
} else if (typeof task === 'object' && task.run) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG && console.log('TaskQueue: run task ' + task.name);
|
||||
task.run();
|
||||
} else {
|
||||
@@ -110,6 +114,8 @@ class TaskQueue {
|
||||
'Expected Function, SimpleTask, or PromiseTask, but got:\n' +
|
||||
JSON.stringify(task, null, 2),
|
||||
);
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG && console.log('TaskQueue: run anonymous task');
|
||||
task();
|
||||
}
|
||||
@@ -139,6 +145,8 @@ class TaskQueue {
|
||||
this._queueStack.length > 1
|
||||
) {
|
||||
this._queueStack.pop();
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG &&
|
||||
console.log('TaskQueue: popped queue: ', {
|
||||
stackIdx,
|
||||
@@ -158,11 +166,17 @@ class TaskQueue {
|
||||
this._queueStack.push({tasks: [], popable: false});
|
||||
const stackIdx = this._queueStack.length - 1;
|
||||
const stackItem = this._queueStack[stackIdx];
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG && console.log('TaskQueue: push new queue: ', {stackIdx});
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG && console.log('TaskQueue: exec gen task ' + task.name);
|
||||
task
|
||||
.gen()
|
||||
.then(() => {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG &&
|
||||
console.log('TaskQueue: onThen for gen task ' + task.name, {
|
||||
stackIdx,
|
||||
|
||||
@@ -646,6 +646,8 @@ class XMLHttpRequest extends EventTarget {
|
||||
this.withCredentials,
|
||||
);
|
||||
};
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (DEBUG_NETWORK_SEND_DELAY) {
|
||||
setTimeout(doSend, DEBUG_NETWORK_SEND_DELAY);
|
||||
} else {
|
||||
|
||||
@@ -35,6 +35,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
endExtras?: Extras,
|
||||
) {
|
||||
if (this._closed) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log(
|
||||
'PerformanceLogger: addTimespan - has closed ignoring: ',
|
||||
@@ -44,6 +46,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
return;
|
||||
}
|
||||
if (this._timespans[key]) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log(
|
||||
'PerformanceLogger: Attempting to add a timespan that already exists ',
|
||||
@@ -79,6 +83,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
this._timespans = {};
|
||||
this._extras = {};
|
||||
this._points = {};
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE) {
|
||||
console.log('PerformanceLogger.js', 'clear');
|
||||
}
|
||||
@@ -92,6 +98,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
}
|
||||
this._extras = {};
|
||||
this._points = {};
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE) {
|
||||
console.log('PerformanceLogger.js', 'clearCompleted');
|
||||
}
|
||||
@@ -130,6 +138,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
}
|
||||
|
||||
logEverything() {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE) {
|
||||
// log timespans
|
||||
for (const key in this._timespans) {
|
||||
@@ -156,6 +166,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
extras?: Extras,
|
||||
) {
|
||||
if (this._closed) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log(
|
||||
'PerformanceLogger: markPoint - has closed ignoring: ',
|
||||
@@ -165,6 +177,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
return;
|
||||
}
|
||||
if (this._points[key] != null) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log(
|
||||
'PerformanceLogger: Attempting to mark a point that has been already logged ',
|
||||
@@ -187,6 +201,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
|
||||
setExtra(key: string, value: ExtraValue) {
|
||||
if (this._closed) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log('PerformanceLogger: setExtra - has closed ignoring: ', key);
|
||||
}
|
||||
@@ -194,6 +210,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
}
|
||||
|
||||
if (this._extras.hasOwnProperty(key)) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log(
|
||||
'PerformanceLogger: Attempting to set an extra that already exists ',
|
||||
@@ -211,6 +229,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
extras?: Extras,
|
||||
) {
|
||||
if (this._closed) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log(
|
||||
'PerformanceLogger: startTimespan - has closed ignoring: ',
|
||||
@@ -221,6 +241,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
}
|
||||
|
||||
if (this._timespans[key]) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log(
|
||||
'PerformanceLogger: Attempting to start a timespan that already exists ',
|
||||
@@ -234,6 +256,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
startTime: timestamp,
|
||||
startExtras: extras,
|
||||
};
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE) {
|
||||
console.log('PerformanceLogger.js', 'start: ' + key);
|
||||
}
|
||||
@@ -245,6 +269,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
extras?: Extras,
|
||||
) {
|
||||
if (this._closed) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log(
|
||||
'PerformanceLogger: stopTimespan - has closed ignoring: ',
|
||||
@@ -256,6 +282,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
|
||||
const timespan = this._timespans[key];
|
||||
if (!timespan || timespan.startTime == null) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log(
|
||||
'PerformanceLogger: Attempting to end a timespan that has not started ',
|
||||
@@ -265,6 +293,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
return;
|
||||
}
|
||||
if (timespan.endTime != null) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE && __DEV__) {
|
||||
console.log(
|
||||
'PerformanceLogger: Attempting to end a timespan that has already ended ',
|
||||
@@ -277,6 +307,8 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
timespan.endExtras = extras;
|
||||
timespan.endTime = timestamp;
|
||||
timespan.totalTime = timespan.endTime - (timespan.startTime || 0);
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (PRINT_TO_CONSOLE) {
|
||||
console.log('PerformanceLogger.js', 'end: ' + key);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "folly/dynamic.h"
|
||||
#include "folly/json/dynamic.h"
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
@@ -7,9 +7,22 @@
|
||||
|
||||
#include "NativeCxxModuleExample.h"
|
||||
#include <react/debug/react_native_assert.h>
|
||||
#include <iomanip>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string to_string_with_precision(double value, int precision = 2) {
|
||||
std::ostringstream oss;
|
||||
oss << std::setprecision(precision) << std::fixed << value;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NativeCxxModuleExample::NativeCxxModuleExample(
|
||||
std::shared_ptr<CallInvoker> jsInvoker)
|
||||
: NativeCxxModuleExampleCxxSpec(std::move(jsInvoker)) {}
|
||||
@@ -126,10 +139,12 @@ std::string NativeCxxModuleExample::getUnion(
|
||||
float x,
|
||||
std::string y,
|
||||
jsi::Object z) {
|
||||
std::string result = "x: " + std::to_string(x) + ", y: " + y + ", z: { ";
|
||||
std::string result =
|
||||
"x: " + to_string_with_precision(x) + ", y: " + y + ", z: { ";
|
||||
if (z.hasProperty(rt, "value")) {
|
||||
result += "value: ";
|
||||
result += std::to_string(z.getProperty(rt, "value").getNumber());
|
||||
result +=
|
||||
to_string_with_precision(z.getProperty(rt, "value").getNumber(), 0);
|
||||
} else if (z.hasProperty(rt, "low")) {
|
||||
result += "low: ";
|
||||
result += z.getProperty(rt, "low").getString(rt).utf8(rt);
|
||||
@@ -201,11 +216,13 @@ void NativeCxxModuleExample::emitCustomDeviceEvent(
|
||||
eventName,
|
||||
[jsInvoker = jsInvoker_](
|
||||
jsi::Runtime& rt, std::vector<jsi::Value>& args) {
|
||||
args.emplace_back(jsi::Value(true));
|
||||
args.emplace_back(jsi::Value(42));
|
||||
args.emplace_back(jsi::String::createFromAscii(rt, "stringArg"));
|
||||
args.emplace_back(bridging::toJs(
|
||||
rt, CustomDeviceEvent{"one", 2, std::nullopt}, jsInvoker));
|
||||
args.emplace_back(jsi::Array::createWithElements(
|
||||
rt,
|
||||
jsi::Value(true),
|
||||
jsi::Value(42),
|
||||
jsi::String::createFromAscii(rt, "stringArg"),
|
||||
bridging::toJs(
|
||||
rt, CustomDeviceEvent{"one", 2, std::nullopt}, jsInvoker)));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,351 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
|
||||
import type {
|
||||
BinaryTreeNode,
|
||||
GraphNode,
|
||||
ObjectStruct,
|
||||
} from '../NativeCxxModuleExample';
|
||||
|
||||
import NativeCxxModuleExample, {
|
||||
EnumInt,
|
||||
EnumNone,
|
||||
EnumStr,
|
||||
} from '../NativeCxxModuleExample';
|
||||
import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter';
|
||||
import NativeFantom from 'react-native/src/private/testing/fantom/specs/NativeFantom';
|
||||
|
||||
describe('NativeCxxModuleExample', () => {
|
||||
it('verifies that the Turbo Module was loaded', () => {
|
||||
expect(NativeCxxModuleExample).not.toBeNull();
|
||||
});
|
||||
|
||||
it('verifies getArray(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getArray([])).toEqual([]);
|
||||
expect(NativeCxxModuleExample?.getArray([null])).toEqual([null]);
|
||||
expect(NativeCxxModuleExample?.getArray([{a: 1, b: '2'}])).toEqual([
|
||||
{a: 1, b: '2'},
|
||||
]);
|
||||
});
|
||||
|
||||
it('verifies getBool(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getBool(false)).toBe(false);
|
||||
expect(NativeCxxModuleExample?.getBool(true)).toBe(true);
|
||||
});
|
||||
|
||||
it('verifies getConstants(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getConstants()).toEqual({
|
||||
const1: true,
|
||||
const2: 69,
|
||||
const3: 'react-native',
|
||||
});
|
||||
});
|
||||
|
||||
it('verifies getCustomEnum(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getCustomEnum(EnumInt.IA)).toBe(EnumInt.IA);
|
||||
});
|
||||
|
||||
it('verifies getCustomHostObject(...) returns the correct values', () => {
|
||||
const customHostObject = NativeCxxModuleExample?.getCustomHostObject();
|
||||
expect(customHostObject).not.toBe(null);
|
||||
if (customHostObject != null) {
|
||||
expect(
|
||||
NativeCxxModuleExample?.consumeCustomHostObject(customHostObject),
|
||||
).toBe('answer42');
|
||||
}
|
||||
});
|
||||
|
||||
it('verifies getBinaryTreeNode(...) returns the correct values', () => {
|
||||
const binaryTreeNode: BinaryTreeNode = {
|
||||
left: {value: 2},
|
||||
value: 4,
|
||||
right: {value: 6},
|
||||
};
|
||||
const result = NativeCxxModuleExample?.getBinaryTreeNode(binaryTreeNode);
|
||||
expect(result).not.toBe(null);
|
||||
if (result != null) {
|
||||
expect(result.left?.left).toBeNull();
|
||||
expect(result.left?.value).toBe(2);
|
||||
expect(result.left?.right).toBeNull();
|
||||
expect(result.value).toBe(4);
|
||||
expect(result.right?.left).toBeNull();
|
||||
expect(result.right?.value).toBe(6);
|
||||
expect(result.right?.right).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('verifies getGraphNode(...) returns the correct values', () => {
|
||||
const graphNode: GraphNode = {
|
||||
label: 'root',
|
||||
neighbors: [{label: 'child1'}, {label: 'child2'}],
|
||||
};
|
||||
const result = NativeCxxModuleExample?.getGraphNode(graphNode);
|
||||
expect(result).not.toBe(null);
|
||||
if (result != null) {
|
||||
expect(result.label).toBe('root');
|
||||
expect(result.neighbors?.length).toBe(4);
|
||||
expect(result.neighbors?.[0].label).toBe('child1');
|
||||
expect(result.neighbors?.[0].neighbors).toBeNull();
|
||||
expect(result.neighbors?.[1].label).toBe('child2');
|
||||
expect(result.neighbors?.[1].neighbors).toBeNull();
|
||||
expect(result.neighbors?.[2].label).toBe('top');
|
||||
expect(result.neighbors?.[2].neighbors).toBeNull();
|
||||
expect(result.neighbors?.[3].label).toBe('down');
|
||||
expect(result.neighbors?.[3].neighbors).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('verifies getNumEnum(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getNumEnum(EnumInt.IA)).toBe(EnumInt.IA);
|
||||
expect(NativeCxxModuleExample?.getNumEnum(EnumInt.IB)).toBe(EnumInt.IB);
|
||||
});
|
||||
|
||||
it('verifies getStrEnum(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getStrEnum(EnumNone.NA)).toBe(EnumStr.SB);
|
||||
expect(NativeCxxModuleExample?.getStrEnum(EnumNone.NB)).toBe(EnumStr.SB);
|
||||
});
|
||||
|
||||
it('verifies getMap(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getMap({a: 0, b: null, c: 3})).toEqual({
|
||||
a: 0,
|
||||
b: null,
|
||||
c: 3,
|
||||
});
|
||||
});
|
||||
|
||||
it('verifies getNumber(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getNumber(0)).toBe(0);
|
||||
expect(NativeCxxModuleExample?.getNumber(Math.pow(2, 53))).toBe(
|
||||
Math.pow(2, 53),
|
||||
);
|
||||
});
|
||||
|
||||
it('verifies getObject(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getObject({a: 2, b: 'two'})).toEqual({
|
||||
a: 2,
|
||||
b: 'two',
|
||||
});
|
||||
expect(
|
||||
NativeCxxModuleExample?.getObject({a: 4, b: 'four', c: 'seven'}),
|
||||
).toEqual({a: 4, b: 'four', c: 'seven'});
|
||||
});
|
||||
|
||||
it('verifies getSet(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getSet([1, 2, 3, 3, 3])).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
it('verifies getString(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getString('')).toBe('');
|
||||
expect(NativeCxxModuleExample?.getString('string')).toBe('string');
|
||||
});
|
||||
|
||||
it('verifies getUnion(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getUnion(2.88, 'Two', {value: 2})).toBe(
|
||||
'x: 2.88, y: Two, z: { value: 2 }',
|
||||
);
|
||||
expect(NativeCxxModuleExample?.getUnion(5.76, 'One', {low: 'value'})).toBe(
|
||||
'x: 5.76, y: One, z: { low: value }',
|
||||
);
|
||||
});
|
||||
|
||||
it('verifies getValue(...) returns the correct values', () => {
|
||||
expect(
|
||||
NativeCxxModuleExample?.getValue(23, 'forty-two', {
|
||||
a: 4,
|
||||
b: 'four',
|
||||
c: 'seven',
|
||||
}),
|
||||
).toEqual({x: 23, y: 'forty-two', z: {a: 4, b: 'four', c: 'seven'}});
|
||||
});
|
||||
|
||||
it('verifies getValueWithCallback(...) returns the correct values', () => {
|
||||
let result = '';
|
||||
NativeCxxModuleExample?.getValueWithCallback((value: string) => {
|
||||
result = value;
|
||||
});
|
||||
NativeFantom.flushMessageQueue(); // Flush the message queue to execute the callback
|
||||
expect(result).toBe('value from callback!');
|
||||
});
|
||||
|
||||
it('verifies setValueCallbackWithSubscription(...) returns the correct values', () => {
|
||||
let result = '';
|
||||
let subscription = NativeCxxModuleExample?.setValueCallbackWithSubscription(
|
||||
(value: string) => {
|
||||
result = value;
|
||||
},
|
||||
);
|
||||
expect(result).toBe('');
|
||||
expect(subscription).not.toBeNull();
|
||||
subscription?.();
|
||||
NativeFantom.flushMessageQueue(); // Flush the message queue to execute the callback
|
||||
expect(result).toBe('value from callback on clean up!');
|
||||
});
|
||||
|
||||
it('verifies getValueWithPromise(...) returns the correct values', () => {
|
||||
{
|
||||
let result = '';
|
||||
let error = '';
|
||||
NativeCxxModuleExample?.getValueWithPromise(false)
|
||||
.then(value => {
|
||||
result = value;
|
||||
})
|
||||
.catch(err => {
|
||||
error = err;
|
||||
});
|
||||
NativeFantom.flushMessageQueue(); // Flush the message queue to execute the callbacks
|
||||
expect(result).toBe('result!');
|
||||
expect(error).toBe('');
|
||||
}
|
||||
{
|
||||
let result = '';
|
||||
let error = '';
|
||||
NativeCxxModuleExample?.getValueWithPromise(true)
|
||||
.then(value => {
|
||||
result = value;
|
||||
})
|
||||
.catch(err => {
|
||||
error = err;
|
||||
});
|
||||
NativeFantom.flushMessageQueue(); // Flush the message queue to execute the callbacks
|
||||
expect(result).toBe('');
|
||||
expect(error.toString()).toBe('Error: intentional promise rejection');
|
||||
}
|
||||
|
||||
it('verifies getWithWithOptionalArgs(...) returns the correct values', () => {
|
||||
expect(NativeCxxModuleExample?.getWithWithOptionalArgs()).toBeNull();
|
||||
expect(NativeCxxModuleExample?.getWithWithOptionalArgs(true)).toBe(true);
|
||||
expect(NativeCxxModuleExample?.getWithWithOptionalArgs(false)).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('verifies voidFunc(...) returns the correct for EventEmitters', () => {
|
||||
let eventEmitterCalled = {
|
||||
onPress: 0,
|
||||
onClick: 0,
|
||||
onChange: 0,
|
||||
onSubmit: 0,
|
||||
onEvent: 0,
|
||||
};
|
||||
let onClickValue: ?string = null;
|
||||
let onChangeValue: ?ObjectStruct = null;
|
||||
let onSubmitValue: ?(ObjectStruct[]) = null;
|
||||
let onEventValue: ?EnumNone = null;
|
||||
NativeCxxModuleExample?.onPress(() => {
|
||||
eventEmitterCalled.onPress++;
|
||||
});
|
||||
NativeCxxModuleExample?.onClick((value: string) => {
|
||||
eventEmitterCalled.onClick++;
|
||||
onClickValue = value;
|
||||
});
|
||||
NativeCxxModuleExample?.onChange((value: ObjectStruct) => {
|
||||
eventEmitterCalled.onChange++;
|
||||
onChangeValue = value;
|
||||
});
|
||||
NativeCxxModuleExample?.onSubmit((value: ObjectStruct[]) => {
|
||||
eventEmitterCalled.onSubmit++;
|
||||
onSubmitValue = value;
|
||||
});
|
||||
NativeCxxModuleExample?.onEvent((value: EnumNone) => {
|
||||
eventEmitterCalled.onEvent++;
|
||||
onEventValue = value;
|
||||
});
|
||||
NativeCxxModuleExample?.voidFunc();
|
||||
NativeFantom.flushMessageQueue(); // Flush the message queue to execute the callbacks
|
||||
|
||||
expect(eventEmitterCalled.onPress).toBe(1);
|
||||
expect(eventEmitterCalled.onClick).toBe(1);
|
||||
expect(eventEmitterCalled.onChange).toBe(1);
|
||||
expect(eventEmitterCalled.onSubmit).toBe(1);
|
||||
expect(eventEmitterCalled.onEvent).toBe(1);
|
||||
|
||||
expect(onClickValue).toBe('value from callback on click!');
|
||||
expect(onChangeValue).toEqual({a: 1, b: 'two'});
|
||||
expect(onSubmitValue).toEqual([
|
||||
{a: 1, b: 'two'},
|
||||
{a: 3, b: 'four'},
|
||||
{a: 5, b: 'six'},
|
||||
]);
|
||||
expect(onEventValue).toBe(EnumNone.NA);
|
||||
});
|
||||
});
|
||||
|
||||
it('verifies voidPromise(...) returns the correct values', () => {
|
||||
let promiseCalled = {
|
||||
result: 0,
|
||||
error: 0,
|
||||
};
|
||||
NativeCxxModuleExample?.voidPromise()
|
||||
.then(_value => promiseCalled.result++)
|
||||
.catch(_err => promiseCalled.error++);
|
||||
NativeFantom.flushMessageQueue(); // Flush the message queue to execute the callbacks
|
||||
expect(promiseCalled.result).toBe(1);
|
||||
expect(promiseCalled.error).toBe(0);
|
||||
});
|
||||
|
||||
it('verifies setMenu(...) returns the correct values', () => {
|
||||
let result: {[key: string]: ?{value: string, flag: boolean}} = {
|
||||
file: null,
|
||||
new: null,
|
||||
};
|
||||
let menu = {
|
||||
label: 'File',
|
||||
onPress: (value: string, flag: boolean) => {
|
||||
result.file = {value, flag};
|
||||
},
|
||||
items: [
|
||||
{
|
||||
label: 'new',
|
||||
onPress: (value: string, flag: boolean) => {
|
||||
result.new = {value, flag};
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
NativeCxxModuleExample?.setMenu(menu);
|
||||
NativeFantom.flushMessageQueue(); // Flush the message queue to execute the callback
|
||||
expect(result.file?.value).toBe('value');
|
||||
expect(result.file?.flag).toBe(true);
|
||||
expect(result.new?.value).toBe('another value');
|
||||
expect(result.new?.flag).toBe(false);
|
||||
});
|
||||
|
||||
it('verifies emitCustomDeviceEvent(...) returns the correct values', () => {
|
||||
let events: {[key: string]: ?string} = {
|
||||
foo: null,
|
||||
bar: null,
|
||||
};
|
||||
RCTDeviceEventEmitter.addListener(
|
||||
'foo',
|
||||
(value: string) => (events.foo = value),
|
||||
);
|
||||
RCTDeviceEventEmitter.addListener(
|
||||
'bar',
|
||||
(value: string) => (events.bar = value),
|
||||
);
|
||||
NativeCxxModuleExample?.emitCustomDeviceEvent('foo');
|
||||
NativeCxxModuleExample?.emitCustomDeviceEvent('bar');
|
||||
|
||||
NativeFantom.flushMessageQueue(); // Flush the message queue to execute the callbacks
|
||||
expect(events.foo).toEqual([
|
||||
true,
|
||||
42,
|
||||
'stringArg',
|
||||
{type: 'one', level: 2},
|
||||
]);
|
||||
expect(events.foo).toEqual([
|
||||
true,
|
||||
42,
|
||||
'stringArg',
|
||||
{type: 'one', level: 2},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -21,8 +21,7 @@
|
||||
#include REACT_NATIVE_APP_COMPONENT_DESCRIPTORS_HEADER
|
||||
#endif
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
namespace facebook::react {
|
||||
|
||||
void registerComponents(
|
||||
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry) {
|
||||
@@ -62,8 +61,7 @@ std::shared_ptr<TurboModule> javaModuleProvider(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
} // namespace facebook::react
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
||||
return facebook::jni::initialize(vm, [] {
|
||||
|
||||
@@ -33,6 +33,8 @@ const DEBUG = false;
|
||||
|
||||
let _listeners: Array<(Info) => void> = [];
|
||||
let _minSampleCount = 10;
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant Condition
|
||||
* roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
let _sampleRate = DEBUG ? 1 : null;
|
||||
|
||||
/**
|
||||
@@ -82,6 +84,8 @@ class FillRateHelper {
|
||||
|
||||
activate() {
|
||||
if (this._enabled && this._samplesStartTime == null) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG && console.debug('FillRateHelper: activate');
|
||||
this._samplesStartTime = global.performance.now();
|
||||
}
|
||||
@@ -93,6 +97,8 @@ class FillRateHelper {
|
||||
}
|
||||
const start = this._samplesStartTime; // const for flow
|
||||
if (start == null) {
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
DEBUG &&
|
||||
console.debug('FillRateHelper: bail on deactivate with no start time');
|
||||
return;
|
||||
@@ -107,6 +113,8 @@ class FillRateHelper {
|
||||
...this._info,
|
||||
total_time_spent,
|
||||
};
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
if (DEBUG) {
|
||||
const derived = {
|
||||
avg_blankness: this._info.pixels_blank / this._info.pixels_sampled,
|
||||
|
||||
@@ -279,6 +279,8 @@ class VirtualizedList extends StateSafePureComponent<
|
||||
const cartOffset = this._listMetrics.cartesianOffset(
|
||||
offset + this._scrollMetrics.visibleLength,
|
||||
);
|
||||
/* $FlowFixMe[constant-condition] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/1v97vimq. */
|
||||
return horizontal ? {x: cartOffset} : {y: cartOffset};
|
||||
} else {
|
||||
return horizontal ? {x: offset} : {y: offset};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -26,6 +26,7 @@ module.exports = {
|
||||
rootDir: path.resolve(__dirname, '../../..') /*:: as string */,
|
||||
roots: [
|
||||
'<rootDir>/packages/react-native',
|
||||
'<rootDir>/packages/rn-tester',
|
||||
'<rootDir>/packages/polyfills',
|
||||
'<rootDir>/private/react-native-fantom',
|
||||
],
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "TesterAppDelegate.h"
|
||||
|
||||
#include <NativeCxxModuleExample/NativeCxxModuleExample.h>
|
||||
#include <folly/dynamic.h>
|
||||
#include <folly/json.h>
|
||||
#include <glog/logging.h>
|
||||
@@ -87,6 +88,8 @@ TesterAppDelegate::TesterAppDelegate(
|
||||
return std::make_shared<NativeCPUTime>(jsInvoker);
|
||||
} else if (name == NativeFantomTestSpecificMethods::kModuleName) {
|
||||
return std::make_shared<NativeFantomTestSpecificMethods>(jsInvoker);
|
||||
} else if (name == NativeCxxModuleExample::kModuleName) {
|
||||
return std::make_shared<NativeCxxModuleExample>(jsInvoker);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user