Skip to content

Commit

Permalink
TurboModule spec checking should accept hstring for string arguments (#…
Browse files Browse the repository at this point in the history
…14322)

* TurboModule spec checking should accept hstring for string arguments

* Change files

* example
  • Loading branch information
acoates-ms authored Jan 31, 2025
1 parent 9ccccd6 commit 4315cad
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "TurboModule spec checking should accept hstring for string arguments",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
20 changes: 20 additions & 0 deletions vnext/Microsoft.ReactNative.Cxx/NativeModules.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,26 @@ constexpr bool MatchInputArg<std::string, std::wstring>() noexcept {
return true;
}

template <>
constexpr bool MatchInputArg<std::string, winrt::hstring>() noexcept {
return true;
}

template <>
constexpr bool MatchInputArg<winrt::hstring, std::string>() noexcept {
return true;
}

template <>
constexpr bool MatchInputArg<std::wstring, winrt::hstring>() noexcept {
return true;
}

template <>
constexpr bool MatchInputArg<winrt::hstring, std::wstring>() noexcept {
return true;
}

template <class TResult, class TInputArgs, class TOutputCallbacks, class TOutputPromises>
struct MethodSignature {
using Result = TResult;
Expand Down
2 changes: 1 addition & 1 deletion vnext/Microsoft.ReactNative/Modules/ClipboardModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void Clipboard::getString(React::ReactPromise<std::string> result) noexcept {
);
}

void Clipboard::setString(std::wstring content) noexcept {
void Clipboard::setString(winrt::hstring content) noexcept {
m_reactContext.UIDispatcher().Post([=] {
DataTransfer::DataPackage data;
data.SetText(content);
Expand Down
2 changes: 1 addition & 1 deletion vnext/Microsoft.ReactNative/Modules/ClipboardModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Clipboard {
void getString(winrt::Microsoft::ReactNative::ReactPromise<std::string> result) noexcept;

REACT_METHOD(setString)
void setString(std::wstring content) noexcept;
void setString(winrt::hstring content) noexcept;

winrt::Microsoft::ReactNative::ReactContext m_reactContext;
};
Expand Down

0 comments on commit 4315cad

Please sign in to comment.