diff --git a/change/react-native-windows-108cd0f8-12f4-4de6-ae3c-4c3f049028ee.json b/change/react-native-windows-108cd0f8-12f4-4de6-ae3c-4c3f049028ee.json new file mode 100644 index 00000000000..1f3c051e9d0 --- /dev/null +++ b/change/react-native-windows-108cd0f8-12f4-4de6-ae3c-4c3f049028ee.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Add Platform.constants.Release on Windows", + "packageName": "react-native-windows", + "email": "vivekjm77@gmail.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Modules/PlatformConstantsWinModule.cpp b/vnext/Microsoft.ReactNative/Modules/PlatformConstantsWinModule.cpp index a9408ea91b5..241e5f2f2f6 100644 --- a/vnext/Microsoft.ReactNative/Modules/PlatformConstantsWinModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/PlatformConstantsWinModule.cpp @@ -7,9 +7,23 @@ #include #include #include +#include namespace Microsoft::ReactNative { +static std::string GetReleaseVersion() noexcept { + try { + const auto versionInfo = winrt::Windows::System::Profile::AnalyticsInfo::VersionInfo(); + const auto version = std::stoull(winrt::to_string(versionInfo.DeviceFamilyVersion())); + return std::to_string((version & 0xFFFF000000000000ULL) >> 48) + "." + + std::to_string((version & 0x0000FFFF00000000ULL) >> 32) + "." + + std::to_string((version & 0x00000000FFFF0000ULL) >> 16) + "." + + std::to_string(version & 0x000000000000FFFFULL); + } catch (...) { + return ""; + } +} + ReactNativeSpecs::PlatformConstantsWindowsSpec_PlatformConstantsWindows PlatformConstants::GetConstants() noexcept { ReactNativeSpecs::PlatformConstantsWindowsSpec_PlatformConstantsWindows constants; @@ -43,6 +57,8 @@ ReactNativeSpecs::PlatformConstantsWindowsSpec_PlatformConstantsWindows Platform } } + constants.Release = GetReleaseVersion(); + return constants; } diff --git a/vnext/src-win/Libraries/Utilities/Platform.windows.js b/vnext/src-win/Libraries/Utilities/Platform.windows.js index a155b172f66..ee48360327c 100644 --- a/vnext/src-win/Libraries/Utilities/Platform.windows.js +++ b/vnext/src-win/Libraries/Utilities/Platform.windows.js @@ -35,6 +35,7 @@ const Platform: PlatformType = { patch: number, }, osVersion: number, + Release: string, } { // $FlowFixMe[object-this-reference] if (this.__constants == null) { diff --git a/vnext/src-win/Libraries/Utilities/PlatformTypes.js b/vnext/src-win/Libraries/Utilities/PlatformTypes.js index add80d374f4..cb0f0ece078 100644 --- a/vnext/src-win/Libraries/Utilities/PlatformTypes.js +++ b/vnext/src-win/Libraries/Utilities/PlatformTypes.js @@ -118,6 +118,7 @@ type WindowsPlatform = { patch: number, }, osVersion: number, + Release: string, }, // $FlowFixMe[unsafe-getters-setters] get isTesting(): boolean, diff --git a/vnext/src-win/src/private/specs_DEPRECATED/modules/NativePlatformConstantsWindows.js b/vnext/src-win/src/private/specs_DEPRECATED/modules/NativePlatformConstantsWindows.js index 9be7be7e290..c97c011cbac 100644 --- a/vnext/src-win/src/private/specs_DEPRECATED/modules/NativePlatformConstantsWindows.js +++ b/vnext/src-win/src/private/specs_DEPRECATED/modules/NativePlatformConstantsWindows.js @@ -29,6 +29,7 @@ export type PlatformConstantsWindows = {| patch: number, |}, osVersion: number, + Release: string, |}; export interface Spec extends TurboModule {