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
15 changes: 3 additions & 12 deletions packages/react-native/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,6 @@ let reactCore = RNTarget(
)

/// React-Fabric.podspec
// [macOS
#if os(macOS)
let reactFabricViewPlatformSources = ["components/view/platform/macos"]
let reactFabricViewPlatformExcludes = ["components/view/platform/cxx"]
#else
let reactFabricViewPlatformSources = ["components/view/platform/cxx"]
let reactFabricViewPlatformExcludes = ["components/view/platform/macos"]
#endif
// macOS]
let reactFabric = RNTarget(
name: .reactFabric,
path: "ReactCommon/react/renderer",
Expand All @@ -440,7 +431,7 @@ let reactFabric = RNTarget(
"components/view/tests",
"components/view/platform/android",
"components/view/platform/windows",
// "components/view/platform/macos", // [macOS]
// [macOS] View dispatch headers select the destination, not the manifest host.
"components/scrollview/tests",
"components/scrollview/platform/android",
"mounting/tests",
Expand All @@ -465,9 +456,9 @@ let reactFabric = RNTarget(
"components/virtualview",
"components/virtualviewexperimental",
"components/root/tests",
] + reactFabricViewPlatformExcludes, // [macOS]
], // [macOS]
dependencies: [.reactNativeDependencies, .reactJsiExecutor, .rctTypesafety, .reactTurboModuleCore, .jsi, .logger, .reactDebug, .reactFeatureFlags, .reactUtils, .reactRuntimeScheduler, .reactCxxReact, .reactRendererDebug, .reactGraphics, .yoga],
sources: ["animations", "attributedstring", "core", "componentregistry", "componentregistry/native", "components/root", "components/view", "components/scrollview", "components/scrollview/platform/cxx", "components/legacyviewmanagerinterop", "dom", "scheduler", "mounting", "observers/events", "telemetry", "consistency", "leakchecker", "uimanager", "uimanager/consistency"] + reactFabricViewPlatformSources // [macOS]
sources: ["animations", "attributedstring", "core", "componentregistry", "componentregistry/native", "components/root", "components/view", "components/scrollview", "components/scrollview/platform/cxx", "components/legacyviewmanagerinterop", "dom", "scheduler", "mounting", "observers/events", "telemetry", "consistency", "leakchecker", "uimanager", "uimanager/consistency"] // [macOS]
)

let reactFabricInputAccessory = RNTarget(
Expand Down
6 changes: 6 additions & 0 deletions packages/react-native/ReactCommon/React-Fabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ Pod::Spec.new do |s|
sss.source_files = "react/renderer/components/view/**/*.{m,mm,cpp,h}" # [macOS]
sss.exclude_files = "react/renderer/components/view/tests", "react/renderer/components/view/platform/android", "react/renderer/components/view/platform/windows" # [macOS]
sss.header_dir = "react/renderer/components/view"
# [macOS Keep dispatch headers separate from the platform headers they include.
sss.header_mappings_dir = ENV['USE_FRAMEWORKS'] ? "./" : "react/renderer/components/view"
sss.osx.exclude_files = "react/renderer/components/view/platform/cxx/**/*.h"
sss.ios.exclude_files = "react/renderer/components/view/platform/macos/**/HostPlatform*.h"
sss.visionos.exclude_files = "react/renderer/components/view/platform/macos/**/HostPlatform*.h"
# macOS]
end

ss.subspec "scrollview" do |sss|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#pragma once

#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif

#if defined(__ANDROID__)
#include "platform/android/react/renderer/components/view/HostPlatformTouch.h"
#elif defined(__APPLE__) && TARGET_OS_OSX
#include "platform/macos/react/renderer/components/view/HostPlatformTouch.h"
#else
#include "platform/cxx/react/renderer/components/view/HostPlatformTouch.h"
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#pragma once

#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif

#if defined(__ANDROID__)
#include "platform/android/react/renderer/components/view/HostPlatformViewEventEmitter.h"
#elif defined(__APPLE__) && TARGET_OS_OSX
#include "platform/macos/react/renderer/components/view/HostPlatformViewEventEmitter.h"
#else
#include "platform/cxx/react/renderer/components/view/HostPlatformViewEventEmitter.h"
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#pragma once

#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif

#if defined(__ANDROID__)
#include "platform/android/react/renderer/components/view/HostPlatformViewProps.h"
#elif defined(__APPLE__) && TARGET_OS_OSX
#include "platform/macos/react/renderer/components/view/HostPlatformViewProps.h"
#else
#include "platform/cxx/react/renderer/components/view/HostPlatformViewProps.h"
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#pragma once

#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif

#if defined(__ANDROID__)
#include "platform/android/react/renderer/components/view/HostPlatformViewTraitsInitializer.h"
#elif defined(__APPLE__) && TARGET_OS_OSX
#include "platform/macos/react/renderer/components/view/HostPlatformViewTraitsInitializer.h"
#else
#include "platform/cxx/react/renderer/components/view/HostPlatformViewTraitsInitializer.h"
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#pragma once

#include "platform/macos/react/renderer/components/view/KeyEvent.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#pragma once

#include "platform/macos/react/renderer/components/view/MouseEvent.h"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

// [macOS]
#if defined(__APPLE__) // [macOS
#include <TargetConditionals.h>
#endif

#if defined(__APPLE__) && TARGET_OS_OSX

#include <react/renderer/components/view/HostPlatformViewEventEmitter.h>
#include <react/renderer/components/view/KeyEvent.h>
Expand Down Expand Up @@ -211,3 +215,5 @@ void HostPlatformViewEventEmitter::onDrop(const DragEvent& dragEvent) const {
}

} // namespace facebook::react

#endif // macOS]
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

#if defined(__APPLE__) // [macOS
#include <TargetConditionals.h>
#endif

#if defined(__APPLE__) && TARGET_OS_OSX

#include "HostPlatformViewProps.h"

#include <algorithm>
Expand Down Expand Up @@ -160,3 +166,5 @@ void HostPlatformViewProps::setProp(


} // namespace facebook::react

#endif // macOS]
104 changes: 104 additions & 0 deletions packages/react-native/scripts/ios-prebuild/__tests__/setup-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @noflow
*/

// [macOS]

'use strict';

jest.mock(
'../../codegen/generate-artifacts-executor/generateFBReactNativeSpecIOS',
() => ({generateFBReactNativeSpecIOS: jest.fn()}),
);
jest.mock('../hermes', () => ({prepareHermesArtifactsAsync: jest.fn()}));
jest.mock('../reactNativeDependencies', () => ({
prepareReactNativeDependenciesArtifactsAsync: jest.fn(),
}));
jest.mock('../utils', () => ({
createFolderIfNotExists: jest.fn(),
createLogger: () => jest.fn(),
}));
jest.mock('child_process', () => ({execSync: jest.fn()}));
jest.mock('fs');

const {setup} = require('../setup');
const fs = require('fs');
const path = require('path');

test('stages canonical view headers and both relative platform trees in both namespaces, replacing stale links', async () => {
const root = '/rn';
const headers = '/build/headers';
const view = 'ReactCommon/react/renderer/components/view';
const names = [
'HostPlatformViewProps.h',
'HostPlatformViewTraitsInitializer.h',
];
const directories = new Map([
[path.join(root, view), names],
[path.join(root, view, 'platform/cxx'), ['react/']],
[path.join(root, view, 'platform/macos'), ['react/']],
]);
for (const platform of ['cxx', 'macos']) {
const base = path.join(root, view, 'platform', platform);
for (const [directory, entries] of [
['react', ['renderer/']],
['react/renderer', ['components/']],
['react/renderer/components', ['view/']],
['react/renderer/components/view', names],
]) {
directories.set(path.join(base, directory), entries);
}
}
const namespaces = [view, 'react/renderer/components/view'];
const linked = new Map(
namespaces.map(namespace => [
path.join(headers, namespace, names[0]),
'stale platform header',
]),
);
fs.readdirSync.mockImplementation(directory =>
(directories.get(directory) ?? []).map(name => ({
name: name.replace(/\/$/, ''),
isFile: () => !name.endsWith('/'),
isDirectory: () => name.endsWith('/'),
})),
);
fs.existsSync.mockImplementation(file => linked.has(file));
fs.linkSync.mockImplementation((source, target) => {
linked.set(target, source);
});
fs.rmSync.mockImplementation(directory => {
for (const file of linked.keys()) {
if (file.startsWith(directory + path.sep)) {
linked.delete(file);
}
}
});

await setup(root, '/build', '1000.0.0', 'Debug');

for (const namespace of namespaces) {
for (const name of names) {
expect(linked.get(path.join(headers, namespace, name))).toBe(
path.join(root, view, name),
);
for (const platform of ['cxx', 'macos']) {
const relative = path.join(
'platform',
platform,
'react/renderer/components/view',
name,
);
expect(linked.get(path.join(headers, namespace, relative))).toBe(
path.join(root, view, relative),
);
}
}
}
});
47 changes: 31 additions & 16 deletions packages/react-native/scripts/ios-prebuild/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ async function setup(
* in the source path, it creates a link in the target path with an
* underscore prefix.
*/
const link = (fromPath /*:string*/, includePath /*:?string*/) => {
const link = (
fromPath /*:string*/,
includePath /*:?string*/,
preserveStructure /*: boolean */ = false, // [macOS]
) => {
const source = path.resolve(root, fromPath);
const target = path.resolve(linksFolder, includePath ?? fromPath);

Expand Down Expand Up @@ -98,7 +102,15 @@ async function setup(

// Create links for subfolders
subfolders.forEach(folder => {
link(path.join(fromPath, String(folder)), includePath);
// [macOS
link(
path.join(fromPath, String(folder)),
preserveStructure
? path.join(includePath ?? fromPath, String(folder))
: includePath,
preserveStructure,
);
// macOS]
});
};

Expand Down Expand Up @@ -187,20 +199,23 @@ async function setup(
link('ReactCommon/react/runtime/platform/ios', 'ReactCommon/react/runtime');
link('ReactCommon/jsitooling/react/runtime', 'ReactCommon/react/runtime');
link('ReactCommon/react/renderer/components/legacyviewmanagerinterop');
link('ReactCommon/react/renderer/components/view');
link(
'ReactCommon/react/renderer/components/view/platform/cxx',
'ReactCommon/react/renderer/components/view',
);
// [macOS - link macOS-specific view platform headers
link(
'ReactCommon/react/renderer/components/view/platform/macos',
'ReactCommon/react/renderer/components/view',
);
link(
'ReactCommon/react/renderer/components/view/platform/macos',
'react/renderer/components/view',
);
// [macOS Preserve the dispatchers' relative platform includes in both namespaces.
const viewPath = 'ReactCommon/react/renderer/components/view';
for (const includePath of [viewPath, 'react/renderer/components/view']) {
// Replace stale hard links from the previously flattened platform headers.
fs.rmSync(path.resolve(linksFolder, includePath), {
recursive: true,
force: true,
});
link(viewPath, includePath);
for (const platform of ['cxx', 'macos']) {
link(
`${viewPath}/platform/${platform}`,
`${includePath}/platform/${platform}`,
true,
);
}
}
// macOS]
link('ReactCommon/react/renderer/mounting');
link('ReactCommon/react/renderer/attributedstring');
Expand Down
Loading