Merge pull request #134 from microsoft/jsvalueFork
Fork JSValueXaml since 0.66 will include more converters we already h…
This commit is contained in:
Коммит
9b43410af9
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "react-native-xaml",
|
||||
"title": "React Native Xaml",
|
||||
"version": "0.0.44",
|
||||
"version": "0.0.45",
|
||||
"description": "Allows using XAML directly, inside of a React Native Windows app",
|
||||
"main": "lib/index.js",
|
||||
"typings": "lib/index.d.ts",
|
||||
|
@ -33,7 +33,8 @@
|
|||
"readmeFilename": "README.md",
|
||||
"dependencies": {
|
||||
"@types/react": "*",
|
||||
"@types/react-native": "*"
|
||||
"@types/react-native": "*",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">= 17.0.1",
|
||||
|
@ -54,7 +55,7 @@
|
|||
"!*.tgz",
|
||||
"CodeGen/*.cs*",
|
||||
"CodeGen/*.json",
|
||||
"CodeGen/tsconfig.json",
|
||||
"tsconfig.json",
|
||||
"*.cmd",
|
||||
"windows/",
|
||||
"lib/",
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
#ifndef MICROSOFT_REACTNATIVE_JSVALUEXAML
|
||||
#define MICROSOFT_REACTNATIVE_JSVALUEXAML
|
||||
#include "CppWinRTIncludes.h"
|
||||
#include "JSValue.h"
|
||||
|
||||
namespace winrt::Microsoft::ReactNative {
|
||||
|
||||
#ifndef CXXUNITTESTS
|
||||
inline void ReadValue(JSValue const &jsValue, xaml::Media::Brush &value) noexcept {
|
||||
value = XamlHelper::BrushFrom([&jsValue](IJSValueWriter const &writer) noexcept { jsValue.WriteTo(writer); });
|
||||
}
|
||||
|
||||
inline void ReadValue(JSValue const &jsValue, Windows::UI::Color &value) noexcept {
|
||||
value = XamlHelper::ColorFrom([&jsValue](IJSValueWriter const &writer) noexcept { jsValue.WriteTo(writer); });
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void ReadValue(JSValue const &jsValue, xaml::Thickness &value) noexcept {
|
||||
if (auto array = jsValue.TryGetArray()) {
|
||||
if (array->size() == 4) {
|
||||
value = xaml::ThicknessHelper::FromLengths(
|
||||
(*array)[0].AsDouble(), (*array)[1].AsDouble(), (*array)[2].AsDouble(), (*array)[3].AsDouble());
|
||||
return;
|
||||
}
|
||||
} else if (auto number = jsValue.TryGetDouble()) {
|
||||
value = xaml::ThicknessHelper::FromUniformLength(*number);
|
||||
} else if (auto numberInt = jsValue.TryGetInt64()) {
|
||||
const auto valueDbl = static_cast<double>(*numberInt);
|
||||
value = xaml::ThicknessHelper::FromUniformLength(valueDbl);
|
||||
} else {
|
||||
const auto &obj = jsValue.AsObject();
|
||||
value = xaml::ThicknessHelper::FromLengths(
|
||||
obj["left"].AsDouble(), obj["top"].AsDouble(), obj["right"].AsDouble(), obj["bottom"].AsDouble());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
inline void ReadValue(JSValue const &jsValue, xaml::CornerRadius &value) noexcept {
|
||||
if (auto array = jsValue.TryGetArray()) {
|
||||
if (array->size() == 4) {
|
||||
value = xaml::CornerRadiusHelper::FromRadii(
|
||||
(*array)[0].AsDouble(), (*array)[1].AsDouble(), (*array)[2].AsDouble(), (*array)[3].AsDouble());
|
||||
return;
|
||||
}
|
||||
} else if (auto number = jsValue.TryGetDouble()) {
|
||||
value = xaml::CornerRadiusHelper::FromUniformRadius(*number);
|
||||
} else if (auto numberInt = jsValue.TryGetInt64()) {
|
||||
const auto valueDbl = static_cast<double>(*numberInt);
|
||||
value = xaml::CornerRadiusHelper::FromUniformRadius(valueDbl);
|
||||
} else {
|
||||
const auto &obj = jsValue.AsObject();
|
||||
value = xaml::CornerRadiusHelper::FromRadii(
|
||||
obj["topLeft"].AsDouble(),
|
||||
obj["topRight"].AsDouble(),
|
||||
obj["bottomRight"].AsDouble(),
|
||||
obj["bottomLeft"].AsDouble());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
inline void ReadValue(JSValue const &jsValue, winrt::Windows::Foundation::Uri &value) noexcept {
|
||||
value = Uri{winrt::to_hstring(jsValue.AsString())};
|
||||
}
|
||||
|
||||
} // namespace winrt::Microsoft::ReactNative
|
||||
|
||||
#endif // MICROSOFT_REACTNATIVE_JSVALUEXAML
|
|
@ -151,6 +151,7 @@
|
|||
<ClInclude Include="Codegen\TypeEvents.g.h" />
|
||||
<ClInclude Include="Codegen\TypeProperties.g.h" />
|
||||
<ClInclude Include="Crc32Str.h" />
|
||||
<ClInclude Include="JSValueXaml_local.h" />
|
||||
<ClInclude Include="ReactPackageProvider.h">
|
||||
<DependentUpon>ReactPackageProvider.idl</DependentUpon>
|
||||
</ClInclude>
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
<ClInclude Include="Codegen\TypeEnums.g.h">
|
||||
<Filter>Codegen</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="JSValueXaml_local.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="PropertySheet.props" />
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <string>
|
||||
#include <JSValue.h>
|
||||
#include <JSValueReader.h>
|
||||
#include <JSValueXaml.h>
|
||||
#include <JSValueXaml_local.h>
|
||||
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <winrt/Windows.UI.Xaml.Controls.Maps.h>
|
||||
|
@ -55,52 +55,6 @@ namespace winrt::Microsoft::ReactNative {
|
|||
inline void ReadValue(JSValue const& jsValue, Windows::UI::Text::FontWeight& value) noexcept {
|
||||
value.Weight = jsValue.AsInt16();
|
||||
}
|
||||
|
||||
inline void ReadValue(JSValue const& jsValue, xaml::Thickness& value) noexcept {
|
||||
if (auto array = jsValue.TryGetArray()) {
|
||||
if (array->size() == 4) {
|
||||
value = ThicknessHelper::FromLengths((*array)[0].AsDouble(), (*array)[1].AsDouble(), (*array)[2].AsDouble(), (*array)[3].AsDouble());
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (auto number = jsValue.TryGetDouble()) {
|
||||
value = ThicknessHelper::FromUniformLength(*number);
|
||||
}
|
||||
else if (auto numberInt = jsValue.TryGetInt64()) {
|
||||
const auto valueDbl = static_cast<double>(*numberInt);
|
||||
value = ThicknessHelper::FromUniformLength(valueDbl);
|
||||
}
|
||||
else {
|
||||
const auto& obj = jsValue.AsObject();
|
||||
value = ThicknessHelper::FromLengths(obj["left"].AsDouble(), obj["top"].AsDouble(), obj["right"].AsDouble(), obj["bottom"].AsDouble());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
inline void ReadValue(JSValue const& jsValue, xaml::CornerRadius& value) noexcept {
|
||||
if (auto array = jsValue.TryGetArray()) {
|
||||
if (array->size() == 4) {
|
||||
value = CornerRadiusHelper::FromRadii((*array)[0].AsDouble(), (*array)[1].AsDouble(), (*array)[2].AsDouble(), (*array)[3].AsDouble());
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (auto number = jsValue.TryGetDouble()) {
|
||||
value = CornerRadiusHelper::FromUniformRadius(*number);
|
||||
}
|
||||
else if (auto numberInt = jsValue.TryGetInt64()) {
|
||||
const auto valueDbl = static_cast<double>(*numberInt);
|
||||
value = CornerRadiusHelper::FromUniformRadius(valueDbl);
|
||||
}
|
||||
else {
|
||||
const auto& obj = jsValue.AsObject();
|
||||
value = CornerRadiusHelper::FromRadii(obj["topLeft"].AsDouble(), obj["topRight"].AsDouble(), obj["bottomRight"].AsDouble(), obj["bottomLeft"].AsDouble());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
inline void ReadValue(JSValue const& jsValue, winrt::Windows::Foundation::Uri& value) noexcept {
|
||||
value = Uri{ winrt::to_hstring(jsValue.AsString()) };
|
||||
}
|
||||
}
|
||||
|
||||
enum class XamlPropType {
|
||||
|
|
Загрузка…
Ссылка в новой задаче