diff --git a/.ado/publish.yml b/.ado/publish.yml index 6f7d028896145f..896f51df9a5729 100644 --- a/.ado/publish.yml +++ b/.ado/publish.yml @@ -72,14 +72,6 @@ jobs: script: node .ado/bumpFileVersions.js condition: and(succeeded(), ne(variables['Build.SourceBranchName'], 'main')) - - task: CmdLine@2 - displayName: pod update React-TurboModuleCxx-RNW - inputs: - script: | - cd packages/rn-tester - pod update React-TurboModuleCxx-RNW - condition: and(succeeded(), ne(variables['Build.SourceBranchName'], 'main')) - - task: CmdLine@2 displayName: Set canary package version inputs: diff --git a/ReactTurboModuleCxx/React-TurboModuleCxx-RNW.podspec b/ReactTurboModuleCxx/React-TurboModuleCxx-RNW.podspec deleted file mode 100644 index 18f917b8029257..00000000000000 --- a/ReactTurboModuleCxx/React-TurboModuleCxx-RNW.podspec +++ /dev/null @@ -1,38 +0,0 @@ -require "json" - -package = JSON.parse(File.read(File.join(__dir__, "..", "package.json"))) -version = package['version'] - -folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' -folly_version = '2021.07.22.00' - -Pod::Spec.new do |s| - s.name = "React-TurboModuleCxx-RNW" - s.version = version - s.summary = "C++ supporting for Turbo Module." - s.homepage = "https://github.com/microsoft/react-native-windows" - s.license = package["license"] - s.author = "Microsoft Corporation" - s.platforms = { :ios => "11.0", :osx => "10.15" } - s.compiler_flags = folly_compiler_flags - s.source = { :git => 'https://github.com/microsoft/react-native-windows.git', - :commit => "d9077991441889ddaa18a8af6a2cc8514ca7714d" } - s.source_files = "vnext/Shared/TurboModuleRegistry.h", - "vnext/Microsoft.ReactNative/JsiReader.{h,cpp}", - "vnext/Microsoft.ReactNative/JsiWriter.{h,cpp}", - "vnext/Microsoft.ReactNative/TurboModulesProvider.{h,cpp}", - "vnext/Microsoft.ReactNative.Cxx/JSValue*.{h,cpp}", - "vnext/Microsoft.ReactNative.Cxx/Module*.{h,cpp}", - "vnext/Microsoft.ReactNative.Cxx/React*.{h,cpp}", - "vnext/Microsoft.ReactNative.Cxx/StructInfo.h", - "vnext/Microsoft.ReactNative.Cxx/NativeModules.h" - s.library = "stdc++" - s.pod_target_xcconfig = { "USE_HEADERMAP" => "YES", - "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" } - - s.dependency "RCT-Folly", folly_version - s.dependency "React-callinvoker", version - s.dependency "ReactCommon/turbomodule/core", version - s.dependency "React-TurboModuleCxx-WinRTPort", version -end diff --git a/ReactTurboModuleCxx/React-TurboModuleCxx-WinRTPort.podspec b/ReactTurboModuleCxx/React-TurboModuleCxx-WinRTPort.podspec deleted file mode 100644 index 729648a57fc80e..00000000000000 --- a/ReactTurboModuleCxx/React-TurboModuleCxx-WinRTPort.podspec +++ /dev/null @@ -1,47 +0,0 @@ -require "json" - -package = JSON.parse(File.read(File.join(__dir__, "..", "package.json"))) -version = package['version'] - -folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' -folly_version = '2021.07.22.00' - -source = { :git => 'https://github.com/microsoft/react-native-macos.git' } -if version == '1000.0.0' - # This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in. - source[:commit] = `git rev-parse HEAD`.strip -else - source[:tag] = "v#{version}" -end - -Pod::Spec.new do |s| - s.name = "React-TurboModuleCxx-WinRTPort" - s.version = version - s.summary = "C++ supporting for Turbo Module." - s.homepage = "https://github.com/microsoft/react-native-macos" - s.license = package["license"] - s.author = "Microsoft Corporation" - s.platforms = { :ios => "11.0", :osx => "10.15" } - s.compiler_flags = folly_compiler_flags - s.source = source - - s.subspec 'Shared' do |ss| - ss.source_files = "Shared/*.{h,cpp,mm}" - ss.library = "stdc++" - ss.pod_target_xcconfig = { "USE_HEADERMAP" => "YES", - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" } - end - - s.subspec 'WinRT' do |ss| - ss.source_files = "WinRT/*.{h,cpp,mm}" - ss.library = "stdc++" - ss.pod_target_xcconfig = { "USE_HEADERMAP" => "YES", - "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" } - ss.header_dir = "winrt" - - ss.dependency "RCT-Folly", folly_version - ss.dependency "React-callinvoker", version - ss.dependency "React-TurboModuleCxx-WinRTPort/Shared", version - end -end diff --git a/ReactTurboModuleCxx/Shared/Crash.h b/ReactTurboModuleCxx/Shared/Crash.h deleted file mode 100644 index 2e415d7c53bf4f..00000000000000 --- a/ReactTurboModuleCxx/Shared/Crash.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -#ifndef VerifyElseCrash -#define VerifyElseCrash(condition) \ - do { \ - if (!(condition)) { \ - assert(false && #condition); \ - std::terminate(); \ - } \ - } while (false) -#endif - -#ifndef VerifyElseCrashSz -#define VerifyElseCrashSz(condition, message) \ - do { \ - if (!(condition)) { \ - assert(false && (message)); \ - std::terminate(); \ - } \ - } while (false) -#endif diff --git a/ReactTurboModuleCxx/Shared/pch.h b/ReactTurboModuleCxx/Shared/pch.h deleted file mode 100644 index d052458257706f..00000000000000 --- a/ReactTurboModuleCxx/Shared/pch.h +++ /dev/null @@ -1 +0,0 @@ -/* dummy file */ \ No newline at end of file diff --git a/ReactTurboModuleCxx/WinRT/Microsoft.ReactNative.MacOS.mm b/ReactTurboModuleCxx/WinRT/Microsoft.ReactNative.MacOS.mm deleted file mode 100644 index 68c18ecd09ba08..00000000000000 --- a/ReactTurboModuleCxx/WinRT/Microsoft.ReactNative.MacOS.mm +++ /dev/null @@ -1,89 +0,0 @@ -#include "Microsoft.ReactNative.h" -#include - -namespace winrt::Microsoft::ReactNative -{ - -struct MacOSUIDispatcher : implements -{ - bool HasThreadAccess() const noexcept - { - VerifyElseCrash(false); - } - void Post(const ReactDispatcherCallback& callback) noexcept - { - auto copy = callback; - dispatch_async(dispatch_get_main_queue(), ^{ - copy(); - }); - } -}; - -struct MacOSJSDispatcher : implements -{ - std::shared_ptr _jsInvoker; - - MacOSJSDispatcher(const std::shared_ptr& jsInvoker) - : _jsInvoker(jsInvoker) - { - } - - bool HasThreadAccess() const noexcept - { - VerifyElseCrash(false); - } - - void Post(const ReactDispatcherCallback& callback) noexcept - { - _jsInvoker->invokeAsync(ReactDispatcherCallback(callback)); - } -}; - -struct MacOSReactContext : implements -{ - IReactDispatcher _uiDispatcher; - IReactDispatcher _jsDispatcher; - - MacOSReactContext(const std::shared_ptr& jsInvoker) - { - _uiDispatcher = make(); - _jsDispatcher = make(jsInvoker); - } - - IReactPropertyBag Properties() const noexcept - { - VerifyElseCrash(false); - } - - IReactNotificationService Notifications() const noexcept - { - VerifyElseCrash(false); - } - - IReactDispatcher UIDispatcher() const noexcept - { - return _uiDispatcher; - } - - IReactDispatcher JSDispatcher() const noexcept - { - return _jsDispatcher; - } - - void CallJSFunction(const hstring& moduleName, const hstring& methodName, const JSValueArgWriter& paramsArgWriter) noexcept - { - VerifyElseCrash(false); - } - - void EmitJSEvent(const hstring& eventEmitterName, const hstring& eventName, const JSValueArgWriter& paramsArgWriter) noexcept - { - VerifyElseCrash(false); - } -}; - -IReactContext CreateMacOSReactContext(const std::shared_ptr& jsInvoker) noexcept -{ - return make(jsInvoker); -} - -} diff --git a/ReactTurboModuleCxx/WinRT/Microsoft.ReactNative.Static.cpp b/ReactTurboModuleCxx/WinRT/Microsoft.ReactNative.Static.cpp deleted file mode 100644 index a3fee5851f3ac7..00000000000000 --- a/ReactTurboModuleCxx/WinRT/Microsoft.ReactNative.Static.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "Microsoft.ReactNative.h" - -namespace winrt::Microsoft::ReactNative -{ - -// ReactDispatcherHelper - -IReactDispatcher ReactDispatcherHelper::CreateSerialDispatcher() noexcept -{ - VerifyElseCrash(false); -} - -// ReactPropertyBagHelper - -IReactPropertyNamespace ReactPropertyBagHelper::GlobalNamespace() noexcept -{ - VerifyElseCrash(false); -} - -IReactPropertyNamespace ReactPropertyBagHelper::GetNamespace(const hstring& namespaceName) noexcept -{ - VerifyElseCrash(false); -} - -IReactPropertyName ReactPropertyBagHelper::GetName(IReactPropertyNamespace ns, const hstring& localName) noexcept -{ - VerifyElseCrash(false); -} - -IReactPropertyBag ReactPropertyBagHelper::CreatePropertyBag() noexcept -{ - VerifyElseCrash(false); -} - -// ReactNotificationServiceHelper - -IReactNotificationService ReactNotificationServiceHelper::CreateNotificationService() noexcept -{ - VerifyElseCrash(false); -} - -} diff --git a/ReactTurboModuleCxx/WinRT/Microsoft.ReactNative.h b/ReactTurboModuleCxx/WinRT/Microsoft.ReactNative.h deleted file mode 100644 index 6e2930bb76214b..00000000000000 --- a/ReactTurboModuleCxx/WinRT/Microsoft.ReactNative.h +++ /dev/null @@ -1,370 +0,0 @@ -#pragma once - -#include "Windows.Foundation.h" -#include - -namespace winrt::Microsoft::ReactNative -{ - -template -decltype(auto) ReadOptional(std::optional &opt) -{ - return opt.__get(); -} - -// IJSValueReader.idl - -enum class JSValueType -{ - Null, - Object, - Array, - String, - Boolean, - Int64, - Double, -}; - -struct IJSValueReader : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual JSValueType ValueType() noexcept = 0; - virtual bool GetNextObjectProperty(hstring &propertyName) noexcept = 0; - virtual bool GetNextArrayItem() noexcept = 0; - virtual hstring GetString() noexcept = 0; - virtual bool GetBoolean() noexcept = 0; - virtual int64_t GetInt64() noexcept = 0; - virtual double GetDouble() noexcept = 0; - }; - - JSValueType ValueType() const noexcept { return get_itf()->ValueType(); } - bool GetNextObjectProperty(hstring &propertyName) const noexcept { return get_itf()->GetNextObjectProperty(propertyName); } - bool GetNextArrayItem() const noexcept { return get_itf()->GetNextArrayItem(); } - hstring GetString() const noexcept { return get_itf()->GetString(); } - bool GetBoolean() const noexcept { return get_itf()->GetBoolean(); } - int64_t GetInt64() const noexcept { return get_itf()->GetInt64(); } - double GetDouble() const noexcept { return get_itf()->GetDouble(); } - - bool GetNextObjectProperty(const std::wstring_view &propertyName) const noexcept - { - auto str = std::wstring(propertyName.cbegin(), propertyName.cend()); - return GetNextObjectProperty(str); - } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IJSValueReader) -}; - -// IJSValueWriter.idl - -struct IJSValueWriter : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual void WriteNull() noexcept = 0; - virtual void WriteBoolean(bool value) noexcept = 0; - virtual void WriteInt64(int64_t value) noexcept = 0; - virtual void WriteDouble(double value) noexcept = 0; - virtual void WriteString(const winrt::hstring &value) noexcept = 0; - virtual void WriteObjectBegin() noexcept = 0; - virtual void WritePropertyName(const winrt::hstring &name) noexcept = 0; - virtual void WriteObjectEnd() noexcept = 0; - virtual void WriteArrayBegin() noexcept = 0; - virtual void WriteArrayEnd() noexcept = 0; - }; - - void WriteNull() const noexcept { get_itf()->WriteNull(); } - void WriteBoolean(bool value) const noexcept { get_itf()->WriteBoolean(value); } - void WriteInt64(int64_t value) const noexcept { get_itf()->WriteInt64(value); } - void WriteDouble(double value) const noexcept { get_itf()->WriteDouble(value); } - void WriteString(const winrt::hstring &value) const noexcept { get_itf()->WriteString(value); } - void WriteObjectBegin() const noexcept { get_itf()->WriteObjectBegin(); } - void WritePropertyName(const winrt::hstring &name) const noexcept { get_itf()->WritePropertyName(name); } - void WriteObjectEnd() const noexcept { get_itf()->WriteObjectEnd(); } - void WriteArrayBegin() const noexcept { get_itf()->WriteArrayBegin(); } - void WriteArrayEnd() const noexcept { get_itf()->WriteArrayEnd(); } - - void WriteString(const wchar_t* value) const noexcept - { - auto str = std::wstring(value); - WriteString(str); - } - - void WriteString(const std::wstring_view &value) const noexcept - { - auto str = std::wstring(value.cbegin(), value.cend()); - WriteString(str); - } - - void WritePropertyName(const std::wstring_view &name) const noexcept - { - auto str = std::wstring(name.cbegin(), name.cend()); - WritePropertyName(str); - } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IJSValueWriter) -}; - -using JSValueArgWriter = std::function; - -// IReactPackageBuilder.idl - -struct IReactModuleBuilder; - -using ReactModuleProvider = std::function; - -struct IReactPackageBuilder : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual void AddModule(const hstring& moduleName, const ReactModuleProvider& moduleProvider) noexcept = 0; - }; - - void AddModule(const hstring& moduleName, const ReactModuleProvider& moduleProvider) const noexcept { get_itf()->AddModule(moduleName, moduleProvider); } - - void AddModule(const wchar_t* moduleName, const ReactModuleProvider& moduleProvider) const noexcept - { - AddModule(moduleName, moduleProvider); - } - - void AddModule(const std::wstring_view& moduleName, const ReactModuleProvider& moduleProvider) const noexcept - { - auto str = std::wstring(moduleName.cbegin(), moduleName.cend()); - AddModule(str, moduleProvider); - } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactPackageBuilder) -}; - -// IReactDispatcher.idl - -using ReactDispatcherCallback = std::function; - -struct IReactDispatcher : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual bool HasThreadAccess() const noexcept = 0; - virtual void Post(const ReactDispatcherCallback& callback) noexcept = 0; - }; - - bool HasThreadAccess() const noexcept { return get_itf()->HasThreadAccess(); } - void Post(const ReactDispatcherCallback& callback) const noexcept { return get_itf()->Post(callback); } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactDispatcher) -}; - -struct ReactDispatcherHelper -{ - static IReactDispatcher CreateSerialDispatcher() noexcept; -}; - -// IReactNonAbiValue.idl - -struct IReactNonAbiValue : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual int64_t GetPtr() const noexcept = 0; - }; - - int64_t GetPtr() const noexcept { return get_itf()->GetPtr(); } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactNonAbiValue) -}; - -// IReactPropertyBag.idl - -using ReactCreatePropertyValue = std::function; - -struct IReactPropertyNamespace : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual hstring NamespaceName() const noexcept = 0; - }; - - hstring NamespaceName() const noexcept { return get_itf()->NamespaceName(); } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactPropertyNamespace) -}; - -struct IReactPropertyName : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual hstring LocalName() const noexcept = 0; - virtual IReactPropertyNamespace Namespace() const noexcept = 0; - }; - - hstring LocalName() const noexcept { return get_itf()->LocalName(); } - IReactPropertyNamespace Namespace() const noexcept { return get_itf()->Namespace(); } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactPropertyName) -}; - -struct IReactPropertyBag : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual IInspectable Get(IReactPropertyName name) noexcept = 0; - virtual IInspectable GetOrCreate(IReactPropertyName name, const ReactCreatePropertyValue& createValue) noexcept = 0; - virtual IInspectable Set(IReactPropertyName name, IInspectable value) noexcept = 0; - }; - - IInspectable Get(IReactPropertyName name) const noexcept { return get_itf()->Get(name); } - IInspectable GetOrCreate(IReactPropertyName name, const ReactCreatePropertyValue& createValue) const noexcept { return get_itf()->GetOrCreate(name, createValue); } - IInspectable Set(IReactPropertyName name, IInspectable value) const noexcept { return get_itf()->Set(name, value); } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactPropertyBag) -}; - -struct ReactPropertyBagHelper -{ - static IReactPropertyNamespace GlobalNamespace() noexcept; - static IReactPropertyNamespace GetNamespace(const hstring& namespaceName) noexcept; - static IReactPropertyName GetName(IReactPropertyNamespace ns, const hstring& localName) noexcept; - static IReactPropertyBag CreatePropertyBag() noexcept; -}; - -// IReactNotificationService.idl - -struct IReactNotificationSubscription : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual IReactPropertyName NotificationName() const noexcept = 0; - virtual IReactDispatcher Dispatcher() const noexcept = 0; - virtual bool IsSubscribed() const noexcept = 0; - virtual void Unsubscribe() noexcept = 0; - }; - - IReactPropertyName NotificationName() const noexcept { return get_itf()->NotificationName(); } - IReactDispatcher Dispatcher() const noexcept { return get_itf()->Dispatcher(); } - bool IsSubscribed() const noexcept { return get_itf()->IsSubscribed(); } - void Unsubscribe() const noexcept { return get_itf()->Unsubscribe(); } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactNotificationSubscription) -}; - -struct IReactNotificationArgs : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual IReactNotificationSubscription Subscription() const noexcept = 0; - virtual IInspectable Data() const noexcept = 0; - }; - - IReactNotificationSubscription Subscription() const noexcept { return get_itf()->Subscription(); } - IInspectable Data() const noexcept { return get_itf()->Data(); } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactNotificationArgs) -}; - -using ReactNotificationHandler = std::function; - -struct IReactNotificationService : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual IReactNotificationSubscription Subscribe(IReactPropertyName notificationName, IReactDispatcher dispatcher, const ReactNotificationHandler& handler) noexcept = 0; - virtual void SendNotification(IReactPropertyName notificationName, IInspectable sender, IInspectable data) noexcept = 0; - }; - - IReactNotificationSubscription Subscribe(IReactPropertyName notificationName, IReactDispatcher dispatcher, const ReactNotificationHandler& handler) const noexcept - { - return get_itf()->Subscribe(notificationName, dispatcher, handler); - } - - void SendNotification(IReactPropertyName notificationName, IInspectable sender, IInspectable data) const noexcept - { - return get_itf()->SendNotification(notificationName, sender, data); - } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactNotificationService) -}; - -struct ReactNotificationServiceHelper -{ - static IReactNotificationService CreateNotificationService() noexcept; -}; - -// IReactContext.idl - -struct IReactContext : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual IReactPropertyBag Properties() const noexcept = 0; - virtual IReactNotificationService Notifications() const noexcept = 0; - virtual IReactDispatcher UIDispatcher() const noexcept = 0; - virtual IReactDispatcher JSDispatcher() const noexcept = 0; - virtual void CallJSFunction(const hstring& moduleName, const hstring& methodName, const JSValueArgWriter& paramsArgWriter) noexcept = 0; - virtual void EmitJSEvent(const hstring& eventEmitterName, const hstring& eventName, const JSValueArgWriter& paramsArgWriter) noexcept = 0; - }; - - IReactPropertyBag Properties() const noexcept { return get_itf()->Properties(); } - IReactNotificationService Notifications() const noexcept { return get_itf()->Notifications(); } - IReactDispatcher UIDispatcher() const noexcept { return get_itf()->UIDispatcher(); } - IReactDispatcher JSDispatcher() const noexcept { return get_itf()->JSDispatcher(); } - void CallJSFunction(const hstring& moduleName, const hstring& methodName, const JSValueArgWriter& paramsArgWriter) const noexcept { return get_itf()->CallJSFunction(moduleName, methodName, paramsArgWriter); } - void EmitJSEvent(const hstring& eventEmitterName, const hstring& eventName, const JSValueArgWriter& paramsArgWriter) const noexcept { return get_itf()->EmitJSEvent(eventEmitterName, eventName, paramsArgWriter); } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactContext) -}; - -// IReactModuleBuilder.idl - -using InitializerDelegate = std::function; - -enum class MethodReturnType -{ - Void, - Callback, - TwoCallbacks, - Promise, -}; - -using MethodResultCallback = std::function; - -using MethodDelegate = std::function; - -using SyncMethodDelegate = std::function; - -using ConstantProviderDelegate = std::function; - -struct IReactModuleBuilder : Windows::Foundation::IInspectable -{ - struct Itf : Windows::Foundation::IInspectable::Itf - { - virtual void AddInitializer(const InitializerDelegate& initializer) noexcept = 0; - virtual void AddConstantProvider(const ConstantProviderDelegate& constantProvider) noexcept = 0; - virtual void AddMethod(const hstring& name, MethodReturnType returnType, const MethodDelegate& method) noexcept = 0; - virtual void AddSyncMethod(const hstring& name, const SyncMethodDelegate& method) noexcept = 0; - }; - - void AddInitializer(InitializerDelegate initializer) const noexcept { return get_itf()->AddInitializer(initializer); } - void AddConstantProvider(ConstantProviderDelegate constantProvider) const noexcept { return get_itf()->AddConstantProvider(constantProvider); } - void AddMethod(const hstring& name, MethodReturnType returnType, MethodDelegate method) const noexcept { return get_itf()->AddMethod(name, returnType, method); } - void AddSyncMethod(const hstring& name, SyncMethodDelegate method) const noexcept { return get_itf()->AddSyncMethod(name, method); } - - void AddMethod(const std::wstring_view& name, MethodReturnType returnType, MethodDelegate method) const noexcept - { - auto str = std::wstring(name.cbegin(), name.cend()); - return get_itf()->AddMethod(str, returnType, method); - } - - void AddSyncMethod(const std::wstring_view& name, SyncMethodDelegate method) const noexcept - { - auto str = std::wstring(name.cbegin(), name.cend()); - return get_itf()->AddSyncMethod(str, method); - } - - WINRT_TO_MAC_MAKE_WINRT_INTERFACE(IReactModuleBuilder) -}; - -// MacOS Helper Functions - -extern IReactContext CreateMacOSReactContext(const std::shared_ptr& jsInvoker) noexcept; - -} diff --git a/ReactTurboModuleCxx/WinRT/Windows.Foundation.h b/ReactTurboModuleCxx/WinRT/Windows.Foundation.h deleted file mode 100644 index fa43f0942a527d..00000000000000 --- a/ReactTurboModuleCxx/WinRT/Windows.Foundation.h +++ /dev/null @@ -1,183 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Crash.h" - -inline int64_t _wcstoi64(const wchar_t* str, wchar_t** str_end, int base) -{ - return std::wcstol(str, str_end, base); -} - -namespace std -{ - -inline std::wstring operator+(const wchar_t* a, const std::wstring_view& b) -{ - return a + std::wstring(b.cbegin(), b.cend()); -} - -} - -namespace winrt -{ - -using hstring = std::wstring; - -inline hstring to_hstring(const std::string& s) -{ - return std::wstring_convert, wchar_t>().from_bytes(s); -} - -inline hstring to_hstring(const char* s) -{ - return std::wstring_convert, wchar_t>().from_bytes(s); -} - -inline hstring to_hstring(const std::string_view& w) -{ - return to_hstring(std::string(w.cbegin(), w.cend())); -} - -inline hstring to_hstring(const std::wstring& s) -{ - return s; -} - -inline hstring to_hstring(const wchar_t* s) -{ - return s; -} - -inline hstring to_hstring(const std::wstring_view& w) -{ - return to_hstring(std::wstring(w.cbegin(), w.cend())); -} - -inline std::string to_string(const hstring& s) -{ - return std::wstring_convert, wchar_t>().to_bytes(s); -} - -template -struct implements : TInterface::Itf -{ - using InterfaceHolder = TInterface; -}; - -template -typename TClass::InterfaceHolder make(TArgs&& ...args) -{ - using TIH = typename TClass::InterfaceHolder; - auto obj = std::make_shared(std::forward(args)...); - std::shared_ptr ptr(obj); - return TIH(obj); -} - -template -TClass* get_self(const TInterface& itf) -{ - return dynamic_cast(itf.get_itf()); -} - -struct take_ownership_from_abi_t{}; -inline const take_ownership_from_abi_t take_ownership_from_abi; - -struct auto_revoke_t{}; -inline const auto_revoke_t auto_revoke; - -struct fire_and_forget{}; - -} - -namespace winrt::param -{ - -using hstring = winrt::hstring; - -} - -#define WINRT_TO_MAC_MAKE_WINRT_INTERFACE(NAME)\ - NAME() = default;\ - NAME(std::nullptr_t){}\ - NAME(const NAME&) = default;\ - NAME(NAME&&) = default;\ - NAME& operator=(const NAME&) = default;\ - NAME& operator=(NAME&&) = default;\ - NAME(const std::shared_ptr& itf):IInspectable(itf){}\ -private:\ - template\ - friend TClass* ::winrt::get_self(const TInterface& itf);\ - Itf* get_itf() const noexcept { return static_cast(m_itf.get()); }\ - -namespace winrt::Windows::Foundation -{ - -struct IInspectable -{ - struct Itf - { - virtual ~Itf() = default; - }; - - IInspectable() noexcept = default; - IInspectable(std::nullptr_t) noexcept {} - IInspectable(const IInspectable&) noexcept = default; - IInspectable(IInspectable&&) noexcept = default; - IInspectable& operator=(const IInspectable&) noexcept = default; - IInspectable& operator=(IInspectable&&) noexcept = default; - operator bool() const noexcept { return m_itf.get() != nullptr; } - - IInspectable(void*, take_ownership_from_abi_t) noexcept - { - VerifyElseCrash(false); - } - - template< - typename TInterface, - typename = std::enable_if_t> - > - TInterface try_as() const noexcept - { - return std::dynamic_pointer_cast(m_itf); - } - - template< - typename TInterface_Itf, - typename = std::enable_if_t> - > - TInterface_Itf* try_as() const noexcept - { - return std::dynamic_pointer_cast(m_itf).get(); - } - - template - auto as()const noexcept - { - auto result = try_as(); - VerifyElseCrash(result); - return result; - } - -protected: - std::shared_ptr m_itf; - - IInspectable(const std::shared_ptr& itf) noexcept - : m_itf(itf) - { - } -}; - -} diff --git a/packages/rn-tester/NativeModuleExample/ScreenshotMacOS.h b/packages/rn-tester/NativeModuleExample/ScreenshotMacOS.h deleted file mode 100644 index 0d04d6207bbcce..00000000000000 --- a/packages/rn-tester/NativeModuleExample/ScreenshotMacOS.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import - -REACT_STRUCT(ScreenshotArguments) -struct ScreenshotArguments {}; - -REACT_MODULE(ScreenshotManagerCxx, L"ScreenshotManager") -struct ScreenshotManagerCxx { - REACT_INIT(Initialize) - void Initialize(const winrt::Microsoft::ReactNative::ReactContext - &reactContext) noexcept { - _reactContext = reactContext; - } - - REACT_METHOD(TakeScreenshot, L"takeScreenshot") - void TakeScreenshot( - std::string, - ScreenshotArguments &&, - winrt::Microsoft::ReactNative::ReactPromise result) noexcept; - - private: - winrt::Microsoft::ReactNative::ReactContext _reactContext; -}; diff --git a/packages/rn-tester/NativeModuleExample/ScreenshotMacOS.mm b/packages/rn-tester/NativeModuleExample/ScreenshotMacOS.mm deleted file mode 100644 index eefc79f9a324d0..00000000000000 --- a/packages/rn-tester/NativeModuleExample/ScreenshotMacOS.mm +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "ScreenshotMacOS.h" - -#import - -static NSImage *TakeScreenshotAsImage() -{ - // find the key window - NSWindow *keyWindow; - for (NSWindow *window in NSApp.windows) { - if (window.keyWindow) { - keyWindow = window; - break; - } - } - - // take a snapshot of the key window - CGWindowID windowID = (CGWindowID)[keyWindow windowNumber]; - CGWindowImageOption imageOptions = kCGWindowImageDefault; - CGWindowListOption listOptions = kCGWindowListOptionIncludingWindow; - CGRect imageBounds = CGRectNull; - CGImageRef windowImage = CGWindowListCreateImage(imageBounds, listOptions, windowID, imageOptions); - NSImage *image = [[NSImage alloc] initWithCGImage:windowImage size:[keyWindow frame].size]; - CGImageRelease(windowImage); - - return image; -} - -static NSString *SaveScreenshotToTempFile(NSImage *image) -{ - // save to a temp file - NSError *error = nil; - NSString *tempFilePath = RCTTempFilePath(@"jpeg", &error); - NSData *imageData = [image TIFFRepresentation]; - NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData]; - NSDictionary *imageProps = [NSDictionary dictionaryWithObject:@0.8 forKey:NSImageCompressionFactor]; - imageData = [imageRep representationUsingType:NSBitmapImageFileTypeJPEG properties:imageProps]; - [imageData writeToFile:tempFilePath atomically:NO]; - - return tempFilePath; -} - -void ScreenshotManagerCxx::TakeScreenshot( - std::string, - ScreenshotArguments &&, - winrt::Microsoft::ReactNative::ReactPromise result) noexcept -{ - _reactContext.UIDispatcher().Post([this, result] { - NSImage *screenshotImage = TakeScreenshotAsImage(); - _reactContext.JSDispatcher().Post([screenshotImage, result]() { - NSString *tempFilePath = SaveScreenshotToTempFile(screenshotImage); - result.Resolve([tempFilePath UTF8String]); - }); - }); -} diff --git a/packages/rn-tester/NativeModuleExample/ScreenshotManager.podspec b/packages/rn-tester/NativeModuleExample/ScreenshotManager.podspec index 0834798660e4ed..b16eb44cdbdeed 100644 --- a/packages/rn-tester/NativeModuleExample/ScreenshotManager.podspec +++ b/packages/rn-tester/NativeModuleExample/ScreenshotManager.podspec @@ -22,9 +22,6 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/facebook/react-native.git", :tag => "#{s.version}" } s.source_files = "**/*.{h,m,mm,swift}" - # [macOS Github#1734: Disable React-TurboModuleCxx RNW implementation as React Native now has C++ sharing support and examples - s.exclude_files = "ScreenshotMacOS.{h,mm}" - # macOS] s.requires_arc = true install_modules_dependencies(s) diff --git a/packages/rn-tester/Podfile b/packages/rn-tester/Podfile index cf5639c8d50311..76bc5cf186aab6 100644 --- a/packages/rn-tester/Podfile +++ b/packages/rn-tester/Podfile @@ -49,11 +49,6 @@ def pods(target_name, options = {}, use_flipper: !IN_CI && !USE_FRAMEWORKS) pod 'Yoga', :path => "#{@prefix_path}/ReactCommon/yoga", :modular_headers => true # Additional Pods which are classed as unstable - # [macOS Github#1734: Disable React-TurboModuleCxx RNW implementation as React Native now has C++ sharing support and examples - # pod 'React-TurboModuleCxx-WinRTPort', :path => "#{@prefix_path}/ReactTurboModuleCxx" - # pod 'React-TurboModuleCxx-RNW', :podspec => "#{@prefix_path}/ReactTurboModuleCxx/React-TurboModuleCxx-RNW.podspec" - # macOS] - # RNTester native modules and components pod 'ScreenshotManager', :path => "NativeModuleExample" end diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm index 59ddc8f79d135d..964e5c99d061df 100644 --- a/packages/rn-tester/RNTester/AppDelegate.mm +++ b/packages/rn-tester/RNTester/AppDelegate.mm @@ -68,7 +68,7 @@ #if !TARGET_OS_OSX // [macOS] @interface AppDelegate () { #else // [macOS -@interface AppDelegate () { // [macOS] +@interface AppDelegate () { #endif // macOS] #ifdef RN_FABRIC_ENABLED RCTSurfacePresenterBridgeAdapter *_bridgeAdapter; @@ -77,10 +77,6 @@ @interface AppDelegate () _turboModulesProvider; -#endif // macOS] } @end @@ -256,16 +252,6 @@ - (Class)getModuleClassFromName:(const char *)name - (std::shared_ptr)getTurboModule:(const std::string &)name jsInvoker:(std::shared_ptr)jsInvoker { - // [macOS Github#1734: Disable React-TurboModuleCxx RNW implementation as React Native now has C++ sharing support and examples - // if (!_turboModulesProvider) { - // _turboModulesProvider = std::make_shared(); - // _turboModulesProvider->SetReactContext(winrt::Microsoft::ReactNative::CreateMacOSReactContext(jsInvoker)); - - // _turboModulesProvider->AddModuleProvider( - // L"ScreenshotManager", winrt::Microsoft::ReactNative::MakeModuleProvider()); - // } - // return _turboModulesProvider->getModule(name, jsInvoker); - // macOS] return facebook::react::RNTesterTurboModuleProvider(name, jsInvoker); }