diff --git a/ios/.clang-format b/.clang-format similarity index 100% rename from ios/.clang-format rename to .clang-format diff --git a/package.json b/package.json index c19238428e..f6c92ab3dc 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,11 @@ "check-types": "tsc --noEmit", "start": "react-native start", "test:unit": "jest --passWithNoTests", - "format": "yarn prettier && yarn clang-format && yarn lint-java", + "format": "yarn prettier && yarn clang-format-ios && yarn clang-format-windows && yarn lint-java", "prettier": "prettier --write --list-different './src/**/*.{js,ts,tsx}'", "lint-java": "node ./scripts/lint-java.js", - "clang-format": "find ios/ -iname *.h -o -iname *.m -o -iname *.cpp | xargs clang-format -i", + "clang-format-ios": "find ios/ -iname *.h -o -iname *.m -o -iname *.cpp | xargs clang-format -i", + "clang-format-windows": "find windows/ -iname *.h -o -iname *.m -o -iname *.cpp | xargs clang-format -i", "lint": "eslint --ext '.js,.ts,.tsx' --fix src && yarn check-types", "precommit": "yarn format && yarn lint", "release": "npm login && release-it", diff --git a/scripts/lint-java.js b/scripts/lint-java.js index 004c2ec8e1..f0f423aaf5 100644 --- a/scripts/lint-java.js +++ b/scripts/lint-java.js @@ -1,197 +1,197 @@ // code taken from facebook/react-native repo - 'use strict'; - - const {exec} = require('shelljs'); - const https = require('https'); - const fs = require('fs'); - const path = require('path'); - const os = require('os'); - const yargs = require('yargs'); - - const googleJavaFormatUrl = - 'https://github.com/google/google-java-format/releases/download/google-java-format-1.7/google-java-format-1.7-all-deps.jar'; - const googleJavaFormatPath = path.join( - os.tmpdir(), - 'google-java-format-all-deps.jar', - ); - const javaFilesCommand = 'find ./android -name "*.java"'; - - function _download(url, downloadPath, resolve, reject, redirectCount) { - https.get(url, response => { - switch (response.statusCode) { - case 302: //Permanent Redirect - if (redirectCount === 0) { - throw new Error( - `Unhandled response code (HTTP${response.statusCode}) while retrieving google-java-format binary from ${url}`, - ); - } - - _download( - response.headers.location, - downloadPath, - resolve, - reject, - redirectCount - 1, - ); - break; - case 200: //OK - const file = fs.createWriteStream(downloadPath); - - response.pipe(file); - file.on('finish', () => file.close(() => resolve())); - break; - default: - reject( - `Unhandled response code (HTTP${response.statusCode}) while retrieving google-java-format binary from ${url}`, - ); - } - }); - } - - function download(url, downloadPath) { - return new Promise((resolve, reject) => { - _download(url, downloadPath, resolve, reject, 1); - }); - } - - function filesWithLintingIssues() { - const proc = exec( - `java -jar ${googleJavaFormatPath} --dry-run $(${javaFilesCommand})`, - {silent: true}, - ); - - if (proc.code !== 0) { - throw new Error(proc.stderr); - } - - return proc.stdout.split('\n').filter(x => x); - } - - function unifiedDiff(file) { - const lintedProc = exec( - `java -jar ${googleJavaFormatPath} --set-exit-if-changed ${file}`, - {silent: true}, - ); - - //Exit code 1 indicates lint violations, which is what we're expecting - if (lintedProc.code !== 1) { - throw new Error(lintedProc.stderr); - } - - const diffProc = lintedProc.exec(`diff -U 0 ${file} -`, {silent: true}); - - //Exit code 0 if inputs are the same, 1 if different, 2 if trouble. - if (diffProc.code !== 0 && diffProc.code !== 1) { - throw new Error(diffProc.stderr); - } - - return { - file, - diff: diffProc.stdout, - }; - } - - function extractRangeInformation(range) { - //eg; - // @@ -54 +54,2 @@ - // @@ -1,3 +1,9 @@ - - const regex = /^@@ [-+](\d+,?\d+) [-+](\d+,?\d+) @@$/; - const match = regex.exec(range); - - if (match) { - const original = match[1].split(','); - const updated = match[2].split(','); - - return { - original: { - line: parseInt(original[0], 10), - lineCount: parseInt(original[1], 10) || 1, - }, - updated: { - line: parseInt(updated[0], 10), - lineCount: parseInt(updated[1], 10) || 1, - }, - }; - } - } - - function parseChanges(file, diff) { - let group = null; - const groups = []; - - diff.split('\n').forEach(line => { - const range = extractRangeInformation(line); - - if (range) { - group = { - range, - description: [line], - }; - groups.push(group); - } else if (group) { - group.description.push(line); - } - }); - - return groups.map(x => ({ - file, - line: x.range.original.line, - lineCount: x.range.original.lineCount, - description: x.description.join('\n'), - })); - } - - async function main() { - const {argv} = yargs - .scriptName('lint-java') - .usage('Usage: $0 [options]') - .command( - '$0', - 'Downloads the google-java-format package and reformats Java source code to comply with Google Java Style.\n\nSee https://github.com/google/google-java-format', - ) - .option('check', { - type: 'boolean', - description: - 'Outputs a list of files with lint violations.\nExit code is set to 1 if there are violations, otherwise 0.\nDoes not reformat lint issues.', - }) - .option('diff', { - type: 'boolean', - description: - 'Outputs a diff of the lint fix changes in json format.\nDoes not reformat lint issues.', - }); - - await download(googleJavaFormatUrl, googleJavaFormatPath); - - if (argv.check) { - const files = filesWithLintingIssues(); - - files.forEach(x => console.log(x)); - - process.exit(files.length === 0 ? 0 : 1); - - } - - if (argv.diff) { - const suggestions = filesWithLintingIssues() - .map(unifiedDiff) - .filter(x => x) - .map(x => parseChanges(x.file, x.diff)) - .reduce((accumulator, current) => accumulator.concat(current), []); - - console.log(JSON.stringify(suggestions)); - - return; - } - - const proc = exec( - `java -jar ${googleJavaFormatPath} --set-exit-if-changed --replace $(${javaFilesCommand})`, - ); - - process.exit(proc.code); - } - - (async () => { - await main(); - })(); +'use strict'; + +const {exec} = require('shelljs'); +const https = require('https'); +const fs = require('fs'); +const path = require('path'); +const os = require('os'); +const yargs = require('yargs'); + +const googleJavaFormatUrl = + 'https://github.com/google/google-java-format/releases/download/google-java-format-1.7/google-java-format-1.7-all-deps.jar'; +const googleJavaFormatPath = path.join( + os.tmpdir(), + 'google-java-format-all-deps.jar', +); +const javaFilesCommand = 'find ./android -name "*.java"'; + +function _download(url, downloadPath, resolve, reject, redirectCount) { + https.get(url, response => { + switch (response.statusCode) { + case 302: //Permanent Redirect + if (redirectCount === 0) { + throw new Error( + `Unhandled response code (HTTP${response.statusCode}) while retrieving google-java-format binary from ${url}`, + ); + } + + _download( + response.headers.location, + downloadPath, + resolve, + reject, + redirectCount - 1, + ); + break; + case 200: //OK + const file = fs.createWriteStream(downloadPath); + + response.pipe(file); + file.on('finish', () => file.close(() => resolve())); + break; + default: + reject( + `Unhandled response code (HTTP${response.statusCode}) while retrieving google-java-format binary from ${url}`, + ); + } + }); +} + +function download(url, downloadPath) { + return new Promise((resolve, reject) => { + _download(url, downloadPath, resolve, reject, 1); + }); +} + +function filesWithLintingIssues() { + const proc = exec( + `java -jar ${googleJavaFormatPath} --dry-run $(${javaFilesCommand})`, + {silent: true}, + ); + + if (proc.code !== 0) { + throw new Error(proc.stderr); + } + + return proc.stdout.split('\n').filter(x => x); +} + +function unifiedDiff(file) { + const lintedProc = exec( + `java -jar ${googleJavaFormatPath} --set-exit-if-changed ${file}`, + {silent: true}, + ); + + //Exit code 1 indicates lint violations, which is what we're expecting + if (lintedProc.code !== 1) { + throw new Error(lintedProc.stderr); + } + + const diffProc = lintedProc.exec(`diff -U 0 ${file} -`, {silent: true}); + + //Exit code 0 if inputs are the same, 1 if different, 2 if trouble. + if (diffProc.code !== 0 && diffProc.code !== 1) { + throw new Error(diffProc.stderr); + } + + return { + file, + diff: diffProc.stdout, + }; +} + +function extractRangeInformation(range) { + //eg; + // @@ -54 +54,2 @@ + // @@ -1,3 +1,9 @@ + + const regex = /^@@ [-+](\d+,?\d+) [-+](\d+,?\d+) @@$/; + const match = regex.exec(range); + + if (match) { + const original = match[1].split(','); + const updated = match[2].split(','); + + return { + original: { + line: parseInt(original[0], 10), + lineCount: parseInt(original[1], 10) || 1, + }, + updated: { + line: parseInt(updated[0], 10), + lineCount: parseInt(updated[1], 10) || 1, + }, + }; + } +} + +function parseChanges(file, diff) { + let group = null; + const groups = []; + + diff.split('\n').forEach(line => { + const range = extractRangeInformation(line); + + if (range) { + group = { + range, + description: [line], + }; + groups.push(group); + } else if (group) { + group.description.push(line); + } + }); + + return groups.map(x => ({ + file, + line: x.range.original.line, + lineCount: x.range.original.lineCount, + description: x.description.join('\n'), + })); +} + +async function main() { + const {argv} = yargs + .scriptName('lint-java') + .usage('Usage: $0 [options]') + .command( + '$0', + 'Downloads the google-java-format package and reformats Java source code to comply with Google Java Style.\n\nSee https://github.com/google/google-java-format', + ) + .option('check', { + type: 'boolean', + description: + 'Outputs a list of files with lint violations.\nExit code is set to 1 if there are violations, otherwise 0.\nDoes not reformat lint issues.', + }) + .option('diff', { + type: 'boolean', + description: + 'Outputs a diff of the lint fix changes in json format.\nDoes not reformat lint issues.', + }); + + await download(googleJavaFormatUrl, googleJavaFormatPath); + + if (argv.check) { + const files = filesWithLintingIssues(); + + files.forEach(x => console.log(x)); + + process.exit(files.length === 0 ? 0 : 1); + + } + + if (argv.diff) { + const suggestions = filesWithLintingIssues() + .map(unifiedDiff) + .filter(x => x) + .map(x => parseChanges(x.file, x.diff)) + .reduce((accumulator, current) => accumulator.concat(current), []); + + console.log(JSON.stringify(suggestions)); + + return; + } + + const proc = exec( + `java -jar ${googleJavaFormatPath} --set-exit-if-changed --replace $(${javaFilesCommand})`, + ); + + process.exit(proc.code); +} + +(async () => { + await main(); +})(); diff --git a/src/index.native.tsx b/src/index.native.tsx index a922df239d..9615cb00ea 100644 --- a/src/index.native.tsx +++ b/src/index.native.tsx @@ -29,7 +29,10 @@ import { } from './types'; // web implementation is taken from `index.tsx` -const isPlatformSupported = Platform.OS === 'ios' || Platform.OS === 'android' || Platform.OS === 'windows'; +const isPlatformSupported = + Platform.OS === 'ios' || + Platform.OS === 'android' || + Platform.OS === 'windows'; let ENABLE_SCREENS = isPlatformSupported; diff --git a/windows/RNScreens/RNScreens.cpp b/windows/RNScreens/RNScreens.cpp index 7c5eabd0d6..bbfc436300 100644 --- a/windows/RNScreens/RNScreens.cpp +++ b/windows/RNScreens/RNScreens.cpp @@ -1,58 +1,66 @@ -#include "pch.h" -#include "JSValueXaml.h" #include "RNScreens.h" +#include "JSValueXaml.h" #include "RNScreensModule.g.cpp" +#include "pch.h" namespace winrt { - using namespace Microsoft::ReactNative; - using namespace Windows::Data::Json; - using namespace Windows::Foundation; - using namespace Windows::UI; - using namespace Windows::UI::Popups; - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; - using namespace Windows::UI::Xaml::Input; - using namespace Windows::UI::Xaml::Media; +using namespace Microsoft::ReactNative; +using namespace Windows::Data::Json; +using namespace Windows::Foundation; +using namespace Windows::UI; +using namespace Windows::UI::Popups; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Input; +using namespace Windows::UI::Xaml::Media; } // namespace winrt namespace winrt::RNScreens::implementation { - RNScreensModule::RNScreensModule(winrt::IReactContext const& reactContext) : m_reactContext(reactContext) { - - } - - winrt::Windows::Foundation::Collections:: - IMapView - RNScreensModule::NativeProps() noexcept { - auto nativeProps = winrt::single_threaded_map(); - return nativeProps.GetView(); - } - - void RNScreensModule::UpdateProperties(winrt::Microsoft::ReactNative::IJSValueReader const& propertyMapReader) noexcept { - const JSValueObject &propertyMap = JSValue::ReadObjectFrom(propertyMapReader); - for (auto const &pair : propertyMap) { - auto const &propertyName = pair.first; - auto const &propertyValue = pair.second; - (void)propertyName; - (void)propertyValue; - } - } - - winrt::Microsoft::ReactNative::ConstantProviderDelegate RNScreensModule::ExportedCustomBubblingEventTypeConstants() noexcept { - return nullptr; - } - - winrt::Microsoft::ReactNative::ConstantProviderDelegate RNScreensModule::ExportedCustomDirectEventTypeConstants() noexcept { - return nullptr; - } - - winrt::Windows::Foundation::Collections::IVectorView RNScreensModule::Commands() noexcept { - return nullptr; - } - - void RNScreensModule::DispatchCommand(winrt::hstring const &commandId, - winrt::Microsoft::ReactNative::IJSValueReader const &commandArgsReader) noexcept { - (void)commandId; - (void)commandArgsReader; - } -} \ No newline at end of file +RNScreensModule::RNScreensModule(winrt::IReactContext const &reactContext) + : m_reactContext(reactContext) {} + +winrt::Windows::Foundation::Collections::IMapView< + winrt::hstring, + winrt::Microsoft::ReactNative::ViewManagerPropertyType> +RNScreensModule::NativeProps() noexcept { + auto nativeProps = + winrt::single_threaded_map(); + return nativeProps.GetView(); +} + +void RNScreensModule::UpdateProperties( + winrt::Microsoft::ReactNative::IJSValueReader const + &propertyMapReader) noexcept { + const JSValueObject &propertyMap = JSValue::ReadObjectFrom(propertyMapReader); + for (auto const &pair : propertyMap) { + auto const &propertyName = pair.first; + auto const &propertyValue = pair.second; + (void)propertyName; + (void)propertyValue; + } +} + +winrt::Microsoft::ReactNative::ConstantProviderDelegate +RNScreensModule::ExportedCustomBubblingEventTypeConstants() noexcept { + return nullptr; +} + +winrt::Microsoft::ReactNative::ConstantProviderDelegate +RNScreensModule::ExportedCustomDirectEventTypeConstants() noexcept { + return nullptr; +} + +winrt::Windows::Foundation::Collections::IVectorView +RNScreensModule::Commands() noexcept { + return nullptr; +} + +void RNScreensModule::DispatchCommand( + winrt::hstring const &commandId, + winrt::Microsoft::ReactNative::IJSValueReader const + &commandArgsReader) noexcept { + (void)commandId; + (void)commandArgsReader; +} +} // namespace winrt::RNScreens::implementation \ No newline at end of file diff --git a/windows/RNScreens/RNScreens.h b/windows/RNScreens/RNScreens.h index 383f91e9a6..ac5faf3a4b 100644 --- a/windows/RNScreens/RNScreens.h +++ b/windows/RNScreens/RNScreens.h @@ -1,35 +1,41 @@ #pragma once -#include "pch.h" -#include "winrt/Microsoft.ReactNative.h" #include "NativeModules.h" #include "RNScreensModule.g.h" +#include "pch.h" +#include "winrt/Microsoft.ReactNative.h" namespace winrt::RNScreens::implementation { - class RNScreensModule : public RNScreensModuleT { - public: - RNScreensModule(Microsoft::ReactNative::IReactContext const& reactContext); - - static winrt::Windows::Foundation::Collections:: - IMapView - NativeProps() noexcept; - void UpdateProperties(winrt::Microsoft::ReactNative::IJSValueReader const& propertyMapReader) noexcept; - - static winrt::Microsoft::ReactNative::ConstantProviderDelegate - ExportedCustomBubblingEventTypeConstants() noexcept; - static winrt::Microsoft::ReactNative::ConstantProviderDelegate - ExportedCustomDirectEventTypeConstants() noexcept; - - static winrt::Windows::Foundation::Collections::IVectorView Commands() noexcept; - void DispatchCommand( - winrt::hstring const &commandId, - winrt::Microsoft::ReactNative::IJSValueReader const &commandArgsReader) noexcept; - private: - Microsoft::ReactNative::IReactContext m_reactContext{ nullptr }; - }; -} +class RNScreensModule : public RNScreensModuleT { + public: + RNScreensModule(Microsoft::ReactNative::IReactContext const &reactContext); + + static winrt::Windows::Foundation::Collections::IMapView< + winrt::hstring, + winrt::Microsoft::ReactNative::ViewManagerPropertyType> + NativeProps() noexcept; + void UpdateProperties(winrt::Microsoft::ReactNative::IJSValueReader const + &propertyMapReader) noexcept; + + static winrt::Microsoft::ReactNative::ConstantProviderDelegate + ExportedCustomBubblingEventTypeConstants() noexcept; + static winrt::Microsoft::ReactNative::ConstantProviderDelegate + ExportedCustomDirectEventTypeConstants() noexcept; + + static winrt::Windows::Foundation::Collections::IVectorView + Commands() noexcept; + void DispatchCommand( + winrt::hstring const &commandId, + winrt::Microsoft::ReactNative::IJSValueReader const + &commandArgsReader) noexcept; + + private: + Microsoft::ReactNative::IReactContext m_reactContext{nullptr}; +}; +} // namespace winrt::RNScreens::implementation namespace winrt::RNScreens::factory_implementation { - struct RNScreensModule : RNScreensModuleT {}; -} +struct RNScreensModule + : RNScreensModuleT {}; +} // namespace winrt::RNScreens::factory_implementation diff --git a/windows/RNScreens/ReactPackageProvider.cpp b/windows/RNScreens/ReactPackageProvider.cpp index 87f5869427..8b24b8e691 100644 --- a/windows/RNScreens/ReactPackageProvider.cpp +++ b/windows/RNScreens/ReactPackageProvider.cpp @@ -1,21 +1,30 @@ -#include "pch.h" #include "ReactPackageProvider.h" +#include "pch.h" #if __has_include("ReactPackageProvider.g.cpp") -# include "ReactPackageProvider.g.cpp" +#include "ReactPackageProvider.g.cpp" #endif -#include "ScreenViewManager.h" +#include "ScreenContainerViewManager.h" #include "ScreenStackHeaderConfigViewManager.h" #include "ScreenStackViewManager.h" -#include "ScreenContainerViewManager.h" +#include "ScreenViewManager.h" using namespace winrt::Microsoft::ReactNative; namespace winrt::RNScreens::implementation { - void ReactPackageProvider::CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept { - packageBuilder.AddViewManager(L"RNScreensViewManager", []() { return winrt::make(); }); - packageBuilder.AddViewManager(L"RNScreensStackHeaderConfigViewManager", []() { return winrt::make(); }); - packageBuilder.AddViewManager(L"RNSScreenStackViewManager", []() { return winrt::make(); }); - packageBuilder.AddViewManager(L"RNSScreenContainerViewManager", []() { return winrt::make(); }); - } +void ReactPackageProvider::CreatePackage( + IReactPackageBuilder const &packageBuilder) noexcept { + packageBuilder.AddViewManager(L"RNScreensViewManager", []() { + return winrt::make(); + }); + packageBuilder.AddViewManager(L"RNScreensStackHeaderConfigViewManager", []() { + return winrt::make(); + }); + packageBuilder.AddViewManager(L"RNSScreenStackViewManager", []() { + return winrt::make(); + }); + packageBuilder.AddViewManager(L"RNSScreenContainerViewManager", []() { + return winrt::make(); + }); } +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ReactPackageProvider.h b/windows/RNScreens/ReactPackageProvider.h index 9ee55c974d..6de8ab73a9 100644 --- a/windows/RNScreens/ReactPackageProvider.h +++ b/windows/RNScreens/ReactPackageProvider.h @@ -4,13 +4,14 @@ using namespace winrt::Microsoft::ReactNative; namespace winrt::RNScreens::implementation { - struct ReactPackageProvider : ReactPackageProviderT { - ReactPackageProvider() = default; - void CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept; - }; -} +struct ReactPackageProvider : ReactPackageProviderT { + ReactPackageProvider() = default; + void CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept; +}; +} // namespace winrt::RNScreens::implementation namespace winrt::RNScreens::factory_implementation { - struct ReactPackageProvider : ReactPackageProviderT {}; -} - +struct ReactPackageProvider : ReactPackageProviderT< + ReactPackageProvider, + implementation::ReactPackageProvider> {}; +} // namespace winrt::RNScreens::factory_implementation diff --git a/windows/RNScreens/Screen.cpp b/windows/RNScreens/Screen.cpp index 3648d59db8..c813463ed1 100644 --- a/windows/RNScreens/Screen.cpp +++ b/windows/RNScreens/Screen.cpp @@ -1,117 +1,121 @@ -#include "pch.h" -#include "NativeModules.h" -#include "JSValueXaml.h" #include "Screen.h" +#include "JSValueXaml.h" +#include "NativeModules.h" +#include "pch.h" namespace winrt { - using namespace Microsoft::ReactNative; - using namespace Windows::Foundation; - using namespace Windows::Foundation::Collections; - using namespace Windows::UI; - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; -} +using namespace Microsoft::ReactNative; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +} // namespace winrt namespace winrt::RNScreens::implementation { - Screen::Screen(winrt::Microsoft::ReactNative::IReactContext reactContext) - : m_reactContext(reactContext) { - onLoadingRevoker = Loading({ this, &Screen::onLoading }); - onLoadedRevoker = Loaded({ this, &Screen::onLoaded }); - onUnloadedRevoker = Unloaded({ this, &Screen::onUnloaded }); - } - - Screen::~Screen() { - Loading(onLoadingRevoker); - Loaded(onLoadedRevoker); - Unloaded(onUnloadedRevoker); - } - - void Screen::addView(winrt::Windows::UI::Xaml::UIElement element) { - Children().Append(element); - } - - void Screen::removeAllChildren() { - Children().Clear(); - } - - void Screen::removeChildAt(int64_t index) { - Children().RemoveAt(static_cast(index)); - } - - void Screen::replaceChild(winrt::Windows::UI::Xaml::UIElement oldChild, - winrt::Windows::UI::Xaml::UIElement newChild) { - uint32_t index; - if (!Children().IndexOf(oldChild, index)) - return; - - Children().SetAt(index, newChild); - } - - void Screen::onLoading(winrt::Windows::UI::Xaml::FrameworkElement const& sender, - winrt::Windows::Foundation::IInspectable const&) { - auto screen = sender.try_as(); - if (!screen) - return; - - screen->dispatchOnWillAppear(); - } - - void Screen::onLoaded(winrt::Windows::Foundation::IInspectable const& sender, - winrt::Windows::UI::Xaml::RoutedEventArgs const&) { - auto screen = sender.try_as(); - if (!screen) - return; - - screen->dispatchOnAppear(); - } - - void Screen::onUnloaded(winrt::Windows::Foundation::IInspectable const& sender, - winrt::Windows::UI::Xaml::RoutedEventArgs const&) { - auto screen = sender.try_as(); - if (!screen) - return; - - screen->dispatchOnWillDisappear(); - screen->dispatchOnDisappear(); - } - - void Screen::dispatchOnWillAppear() { - m_reactContext.DispatchEvent( - *this, - L"topWillAppear", - [&](winrt::IJSValueWriter const& eventDataWriter) noexcept { - eventDataWriter.WriteObjectBegin(); - eventDataWriter.WriteObjectEnd(); - }); - } - - void Screen::dispatchOnWillDisappear() { - m_reactContext.DispatchEvent( - *this, - L"topWillDisappear", - [&](winrt::IJSValueWriter const& eventDataWriter) noexcept { - eventDataWriter.WriteObjectBegin(); - eventDataWriter.WriteObjectEnd(); - }); - } - - void Screen::dispatchOnAppear() { - m_reactContext.DispatchEvent( - *this, - L"topAppear", - [&](winrt::IJSValueWriter const& eventDataWriter) noexcept { - eventDataWriter.WriteObjectBegin(); - eventDataWriter.WriteObjectEnd(); - }); - } - - void Screen::dispatchOnDisappear() { - m_reactContext.DispatchEvent( - *this, - L"topDisappear", - [&](winrt::IJSValueWriter const& eventDataWriter) noexcept { - eventDataWriter.WriteObjectBegin(); - eventDataWriter.WriteObjectEnd(); - }); - } +Screen::Screen(winrt::Microsoft::ReactNative::IReactContext reactContext) + : m_reactContext(reactContext) { + onLoadingRevoker = Loading({this, &Screen::onLoading}); + onLoadedRevoker = Loaded({this, &Screen::onLoaded}); + onUnloadedRevoker = Unloaded({this, &Screen::onUnloaded}); +} + +Screen::~Screen() { + Loading(onLoadingRevoker); + Loaded(onLoadedRevoker); + Unloaded(onUnloadedRevoker); +} + +void Screen::addView(winrt::Windows::UI::Xaml::UIElement element) { + Children().Append(element); +} + +void Screen::removeAllChildren() { + Children().Clear(); +} + +void Screen::removeChildAt(int64_t index) { + Children().RemoveAt(static_cast(index)); +} + +void Screen::replaceChild( + winrt::Windows::UI::Xaml::UIElement oldChild, + winrt::Windows::UI::Xaml::UIElement newChild) { + uint32_t index; + if (!Children().IndexOf(oldChild, index)) + return; + + Children().SetAt(index, newChild); +} + +void Screen::onLoading( + winrt::Windows::UI::Xaml::FrameworkElement const &sender, + winrt::Windows::Foundation::IInspectable const &) { + auto screen = sender.try_as(); + if (!screen) + return; + + screen->dispatchOnWillAppear(); +} + +void Screen::onLoaded( + winrt::Windows::Foundation::IInspectable const &sender, + winrt::Windows::UI::Xaml::RoutedEventArgs const &) { + auto screen = sender.try_as(); + if (!screen) + return; + + screen->dispatchOnAppear(); +} + +void Screen::onUnloaded( + winrt::Windows::Foundation::IInspectable const &sender, + winrt::Windows::UI::Xaml::RoutedEventArgs const &) { + auto screen = sender.try_as(); + if (!screen) + return; + + screen->dispatchOnWillDisappear(); + screen->dispatchOnDisappear(); +} + +void Screen::dispatchOnWillAppear() { + m_reactContext.DispatchEvent( + *this, + L"topWillAppear", + [&](winrt::IJSValueWriter const &eventDataWriter) noexcept { + eventDataWriter.WriteObjectBegin(); + eventDataWriter.WriteObjectEnd(); + }); +} + +void Screen::dispatchOnWillDisappear() { + m_reactContext.DispatchEvent( + *this, + L"topWillDisappear", + [&](winrt::IJSValueWriter const &eventDataWriter) noexcept { + eventDataWriter.WriteObjectBegin(); + eventDataWriter.WriteObjectEnd(); + }); +} + +void Screen::dispatchOnAppear() { + m_reactContext.DispatchEvent( + *this, + L"topAppear", + [&](winrt::IJSValueWriter const &eventDataWriter) noexcept { + eventDataWriter.WriteObjectBegin(); + eventDataWriter.WriteObjectEnd(); + }); +} + +void Screen::dispatchOnDisappear() { + m_reactContext.DispatchEvent( + *this, + L"topDisappear", + [&](winrt::IJSValueWriter const &eventDataWriter) noexcept { + eventDataWriter.WriteObjectBegin(); + eventDataWriter.WriteObjectEnd(); + }); } +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/Screen.h b/windows/RNScreens/Screen.h index 46775f5b15..35c43b1536 100644 --- a/windows/RNScreens/Screen.h +++ b/windows/RNScreens/Screen.h @@ -2,71 +2,63 @@ namespace winrt::RNScreens::implementation { - enum class StackPresentation { - PUSH, - MODAL, - TRANSPARENT_MODAL - }; +enum class StackPresentation { PUSH, MODAL, TRANSPARENT_MODAL }; - enum class StackAnimation { - DEFAULT, - NONE, - FADE, - SIMPLE_FROM_BOTTOM, - SLIDE_FROM_RIGHT, - SLIDE_FROM_LEFT - }; +enum class StackAnimation { + DEFAULT, + NONE, + FADE, + SIMPLE_FROM_BOTTOM, + SLIDE_FROM_RIGHT, + SLIDE_FROM_LEFT +}; - enum class ReplaceAnimation { - PUSH, - POP - }; +enum class ReplaceAnimation { PUSH, POP }; - enum class ActivityState { - INACTIVE, - TRANSITIONING_OR_BELOW_TOP, - ON_TOP - }; +enum class ActivityState { INACTIVE, TRANSITIONING_OR_BELOW_TOP, ON_TOP }; - enum class WindowTraits { - ORIENTATION, - COLOR, - STYLE, - TRANSLUCENT, - HIDDEN, - ANIMATED - }; +enum class WindowTraits { + ORIENTATION, + COLOR, + STYLE, + TRANSLUCENT, + HIDDEN, + ANIMATED +}; - class Screen : public winrt::Windows::UI::Xaml::Controls::StackPanelT { - public: - Screen(winrt::Microsoft::ReactNative::IReactContext reactContext); - ~Screen(); +class Screen : public winrt::Windows::UI::Xaml::Controls::StackPanelT { + public: + Screen(winrt::Microsoft::ReactNative::IReactContext reactContext); + ~Screen(); - void addView(winrt::Windows::UI::Xaml::UIElement element); - void removeAllChildren(); - void removeChildAt(int64_t index); - void replaceChild(winrt::Windows::UI::Xaml::UIElement oldChild, - winrt::Windows::UI::Xaml::UIElement newChild); + void addView(winrt::Windows::UI::Xaml::UIElement element); + void removeAllChildren(); + void removeChildAt(int64_t index); + void replaceChild( + winrt::Windows::UI::Xaml::UIElement oldChild, + winrt::Windows::UI::Xaml::UIElement newChild); - winrt::event_token onLoadingRevoker; - void onLoading(winrt::Windows::UI::Xaml::FrameworkElement const& sender, - winrt::Windows::Foundation::IInspectable const& args); + winrt::event_token onLoadingRevoker; + void onLoading( + winrt::Windows::UI::Xaml::FrameworkElement const &sender, + winrt::Windows::Foundation::IInspectable const &args); - winrt::event_token onLoadedRevoker; - void onLoaded(winrt::Windows::Foundation::IInspectable const& sender, - winrt::Windows::UI::Xaml::RoutedEventArgs const& args); + winrt::event_token onLoadedRevoker; + void onLoaded( + winrt::Windows::Foundation::IInspectable const &sender, + winrt::Windows::UI::Xaml::RoutedEventArgs const &args); - winrt::event_token onUnloadedRevoker; - void onUnloaded(winrt::Windows::Foundation::IInspectable const& sender, - winrt::Windows::UI::Xaml::RoutedEventArgs const& args); + winrt::event_token onUnloadedRevoker; + void onUnloaded( + winrt::Windows::Foundation::IInspectable const &sender, + winrt::Windows::UI::Xaml::RoutedEventArgs const &args); - void dispatchOnAppear(); - void dispatchOnDisappear(); - void dispatchOnWillAppear(); - void dispatchOnWillDisappear(); + void dispatchOnAppear(); + void dispatchOnDisappear(); + void dispatchOnWillAppear(); + void dispatchOnWillDisappear(); - private: - - winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr }; - }; -} + private: + winrt::Microsoft::ReactNative::IReactContext m_reactContext{nullptr}; +}; +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenContainer.cpp b/windows/RNScreens/ScreenContainer.cpp index 5f23c8bf17..6fdb80a83e 100644 --- a/windows/RNScreens/ScreenContainer.cpp +++ b/windows/RNScreens/ScreenContainer.cpp @@ -1,47 +1,49 @@ -#include "pch.h" -#include "NativeModules.h" -#include "JSValueXaml.h" #include "ScreenContainer.h" +#include "JSValueXaml.h" +#include "NativeModules.h" +#include "pch.h" namespace winrt { - using namespace Microsoft::ReactNative; - using namespace Windows::Foundation; - using namespace Windows::Foundation::Collections; - using namespace Windows::UI; - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; -} +using namespace Microsoft::ReactNative; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +} // namespace winrt namespace winrt::RNScreens::implementation { - ScreenContainer::ScreenContainer(winrt::Microsoft::ReactNative::IReactContext reactContext) - : m_reactContext(reactContext), - m_children({ winrt::single_threaded_vector() }) { - } - - void ScreenContainer::addScreen(Screen& screen, int64_t) { - auto uiElement = screen.try_as(); - if (!uiElement) - return; - - m_children.Append(uiElement); - Content(uiElement); - } - - void ScreenContainer::removeAllChildren() { - Content(nullptr); - m_children.Clear(); - } - - void ScreenContainer::removeChildAt(int64_t index) { - m_children.RemoveAt(static_cast(index)); - } - - void ScreenContainer::replaceChild(winrt::Windows::UI::Xaml::UIElement oldChild, - winrt::Windows::UI::Xaml::UIElement newChild) { - uint32_t index; - if (!m_children.IndexOf(oldChild, index)) - return; - - m_children.SetAt(index, newChild); - } +ScreenContainer::ScreenContainer( + winrt::Microsoft::ReactNative::IReactContext reactContext) + : m_reactContext(reactContext), + m_children( + {winrt::single_threaded_vector()}) {} + +void ScreenContainer::addScreen(Screen &screen, int64_t) { + auto uiElement = screen.try_as(); + if (!uiElement) + return; + + m_children.Append(uiElement); + Content(uiElement); +} + +void ScreenContainer::removeAllChildren() { + Content(nullptr); + m_children.Clear(); +} + +void ScreenContainer::removeChildAt(int64_t index) { + m_children.RemoveAt(static_cast(index)); +} + +void ScreenContainer::replaceChild( + winrt::Windows::UI::Xaml::UIElement oldChild, + winrt::Windows::UI::Xaml::UIElement newChild) { + uint32_t index; + if (!m_children.IndexOf(oldChild, index)) + return; + + m_children.SetAt(index, newChild); } +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenContainer.h b/windows/RNScreens/ScreenContainer.h index 494699da2e..6466a50ad1 100644 --- a/windows/RNScreens/ScreenContainer.h +++ b/windows/RNScreens/ScreenContainer.h @@ -2,18 +2,22 @@ #include "Screen.h" namespace winrt::RNScreens::implementation { - class ScreenContainer : public winrt::Windows::UI::Xaml::Controls::ContentControlT { - public: - ScreenContainer(winrt::Microsoft::ReactNative::IReactContext reactContext); - void addScreen(Screen& screen, int64_t index); - void removeAllChildren(); - void removeChildAt(int64_t index); - void replaceChild(winrt::Windows::UI::Xaml::UIElement oldChild, - winrt::Windows::UI::Xaml::UIElement newChild); +class ScreenContainer + : public winrt::Windows::UI::Xaml::Controls::ContentControlT< + ScreenContainer> { + public: + ScreenContainer(winrt::Microsoft::ReactNative::IReactContext reactContext); + void addScreen(Screen &screen, int64_t index); + void removeAllChildren(); + void removeChildAt(int64_t index); + void replaceChild( + winrt::Windows::UI::Xaml::UIElement oldChild, + winrt::Windows::UI::Xaml::UIElement newChild); - winrt::Windows::Foundation::Collections::IVector m_children; + winrt::Windows::Foundation::Collections::IVector + m_children; - private: - winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr }; - }; -} + private: + winrt::Microsoft::ReactNative::IReactContext m_reactContext{nullptr}; +}; +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenContainerViewManager.cpp b/windows/RNScreens/ScreenContainerViewManager.cpp index eef756e474..3fe0ff1bba 100644 --- a/windows/RNScreens/ScreenContainerViewManager.cpp +++ b/windows/RNScreens/ScreenContainerViewManager.cpp @@ -1,120 +1,133 @@ -#include "pch.h" -#include "NativeModules.h" -#include "JSValueXaml.h" #include "ScreenContainerViewManager.h" -#include "ScreenContainer.h" +#include "JSValueXaml.h" +#include "NativeModules.h" #include "Screen.h" +#include "ScreenContainer.h" +#include "pch.h" namespace winrt { - using namespace Microsoft::ReactNative; - using namespace Windows::Foundation; - using namespace Windows::Foundation::Collections; - using namespace Windows::UI; - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; -} +using namespace Microsoft::ReactNative; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +} // namespace winrt namespace winrt::RNScreens::implementation { - // IViewManager - winrt::hstring ScreenContainerViewManager::Name() noexcept { - return L"RNSScreenContainer"; - } - - winrt::FrameworkElement ScreenContainerViewManager::CreateView() noexcept { - return winrt::make(m_reactContext); - } - - // IViewManagerRequiresNativeLayout - bool ScreenContainerViewManager::RequiresNativeLayout() { - return false; - } - - // IViewManagerWithChildren - void ScreenContainerViewManager::AddView(FrameworkElement parent, UIElement child, int64_t index) { - auto screenContainer = parent.as(); - if (!screenContainer) - return; - - auto screen = child.as(); - if (!screen) - return; - - screenContainer->addScreen(*screen, index); - } - - void ScreenContainerViewManager::RemoveAllChildren(FrameworkElement parent) { - auto screenContainer = parent.as(); - if (!screenContainer) - return; - - screenContainer->removeAllChildren(); - } - - void ScreenContainerViewManager::RemoveChildAt(FrameworkElement parent, int64_t index) { - auto screenContainer = parent.as(); - if (!screenContainer) - return; - - screenContainer->removeChildAt(index); - } - - void ScreenContainerViewManager::ReplaceChild(FrameworkElement parent, UIElement oldChild, UIElement newChild) { - auto screenContainer = parent.as(); - if (!screenContainer) - return; - - screenContainer->replaceChild(oldChild, newChild); - } - - // IViewManagerWithReactContext - winrt::IReactContext ScreenContainerViewManager::ReactContext() noexcept { - return m_reactContext; - } - - void ScreenContainerViewManager::ReactContext(IReactContext reactContext) noexcept { - m_reactContext = reactContext; - } - - // IViewManagerWithNativeProperties - IMapView ScreenContainerViewManager::NativeProps() noexcept { - auto nativeProps = winrt::single_threaded_map(); - return nativeProps.GetView(); - } - - void ScreenContainerViewManager::UpdateProperties( - FrameworkElement const& view, - IJSValueReader const& propertyMapReader) noexcept { - (void)view; - const JSValueObject& propertyMap = JSValue::ReadObjectFrom(propertyMapReader); - for (auto const& pair : propertyMap) { - auto const& propertyName = pair.first; - auto const& propertyValue = pair.second; - (void)propertyName; - (void)propertyValue; - } - } - - // IViewManagerWithExportedEventTypeConstants - ConstantProviderDelegate ScreenContainerViewManager::ExportedCustomBubblingEventTypeConstants() noexcept { - return nullptr; - } - - ConstantProviderDelegate ScreenContainerViewManager::ExportedCustomDirectEventTypeConstants() noexcept { - return nullptr; - } - - // IViewManagerWithCommands - IVectorView ScreenContainerViewManager::Commands() noexcept { - auto commands = winrt::single_threaded_vector(); - return commands.GetView(); - } - - void ScreenContainerViewManager::DispatchCommand( - FrameworkElement const& view, - winrt::hstring const& commandId, - winrt::IJSValueReader const& commandArgsReader) noexcept { - (void)view; - (void)commandId; - (void)commandArgsReader; - } +// IViewManager +winrt::hstring ScreenContainerViewManager::Name() noexcept { + return L"RNSScreenContainer"; +} + +winrt::FrameworkElement ScreenContainerViewManager::CreateView() noexcept { + return winrt::make(m_reactContext); +} + +// IViewManagerRequiresNativeLayout +bool ScreenContainerViewManager::RequiresNativeLayout() { + return false; +} + +// IViewManagerWithChildren +void ScreenContainerViewManager::AddView( + FrameworkElement parent, + UIElement child, + int64_t index) { + auto screenContainer = parent.as(); + if (!screenContainer) + return; + + auto screen = child.as(); + if (!screen) + return; + + screenContainer->addScreen(*screen, index); +} + +void ScreenContainerViewManager::RemoveAllChildren(FrameworkElement parent) { + auto screenContainer = parent.as(); + if (!screenContainer) + return; + + screenContainer->removeAllChildren(); +} + +void ScreenContainerViewManager::RemoveChildAt( + FrameworkElement parent, + int64_t index) { + auto screenContainer = parent.as(); + if (!screenContainer) + return; + + screenContainer->removeChildAt(index); +} + +void ScreenContainerViewManager::ReplaceChild( + FrameworkElement parent, + UIElement oldChild, + UIElement newChild) { + auto screenContainer = parent.as(); + if (!screenContainer) + return; + + screenContainer->replaceChild(oldChild, newChild); +} + +// IViewManagerWithReactContext +winrt::IReactContext ScreenContainerViewManager::ReactContext() noexcept { + return m_reactContext; +} + +void ScreenContainerViewManager::ReactContext( + IReactContext reactContext) noexcept { + m_reactContext = reactContext; +} + +// IViewManagerWithNativeProperties +IMapView +ScreenContainerViewManager::NativeProps() noexcept { + auto nativeProps = + winrt::single_threaded_map(); + return nativeProps.GetView(); +} + +void ScreenContainerViewManager::UpdateProperties( + FrameworkElement const &view, + IJSValueReader const &propertyMapReader) noexcept { + (void)view; + const JSValueObject &propertyMap = JSValue::ReadObjectFrom(propertyMapReader); + for (auto const &pair : propertyMap) { + auto const &propertyName = pair.first; + auto const &propertyValue = pair.second; + (void)propertyName; + (void)propertyValue; + } +} + +// IViewManagerWithExportedEventTypeConstants +ConstantProviderDelegate ScreenContainerViewManager:: + ExportedCustomBubblingEventTypeConstants() noexcept { + return nullptr; +} + +ConstantProviderDelegate +ScreenContainerViewManager::ExportedCustomDirectEventTypeConstants() noexcept { + return nullptr; +} + +// IViewManagerWithCommands +IVectorView ScreenContainerViewManager::Commands() noexcept { + auto commands = winrt::single_threaded_vector(); + return commands.GetView(); +} + +void ScreenContainerViewManager::DispatchCommand( + FrameworkElement const &view, + winrt::hstring const &commandId, + winrt::IJSValueReader const &commandArgsReader) noexcept { + (void)view; + (void)commandId; + (void)commandArgsReader; } +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenContainerViewManager.h b/windows/RNScreens/ScreenContainerViewManager.h index 48e787e127..1578ff4d0c 100644 --- a/windows/RNScreens/ScreenContainerViewManager.h +++ b/windows/RNScreens/ScreenContainerViewManager.h @@ -1,62 +1,78 @@ #pragma once -#include "winrt/Microsoft.ReactNative.h" #include "NativeModules.h" +#include "winrt/Microsoft.ReactNative.h" namespace winrt::RNScreens::implementation { - - class ScreenContainerViewManager : public winrt::implements< - ScreenContainerViewManager, - winrt::Microsoft::ReactNative::IViewManager, - winrt::Microsoft::ReactNative::IViewManagerRequiresNativeLayout, - winrt::Microsoft::ReactNative::IViewManagerWithChildren, - winrt::Microsoft::ReactNative::IViewManagerWithReactContext, - winrt::Microsoft::ReactNative::IViewManagerWithNativeProperties, - winrt::Microsoft::ReactNative::IViewManagerWithExportedEventTypeConstants, - winrt::Microsoft::ReactNative::IViewManagerWithCommands> { - public: - ScreenContainerViewManager() = default; - - // IViewManager - winrt::hstring Name() noexcept; - winrt::Windows::UI::Xaml::FrameworkElement CreateView() noexcept; - - // IViewManagerRequiresNativeLayout - bool RequiresNativeLayout(); - - // IViewManagerWithChildren - void AddView(winrt::Windows::UI::Xaml::FrameworkElement parent, winrt::Windows::UI::Xaml::UIElement child, int64_t index); - void RemoveAllChildren(winrt::Windows::UI::Xaml::FrameworkElement parent); - void RemoveChildAt(winrt::Windows::UI::Xaml::FrameworkElement parent, int64_t index); - void ReplaceChild(winrt::Windows::UI::Xaml::FrameworkElement parent, winrt::Windows::UI::Xaml::UIElement oldChild, winrt::Windows::UI::Xaml::UIElement newChild); - - // IViewManagerWithReactContext - winrt::Microsoft::ReactNative::IReactContext ReactContext() noexcept; - void ReactContext(winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept; - - // IViewManagerWithNativeProperties - winrt::Windows::Foundation::Collections:: - IMapView - NativeProps() noexcept; - - void UpdateProperties( - winrt::Windows::UI::Xaml::FrameworkElement const& view, - winrt::Microsoft::ReactNative::IJSValueReader const& propertyMapReader) noexcept; - - // IViewManagerWithExportedEventTypeConstants - winrt::Microsoft::ReactNative::ConstantProviderDelegate ExportedCustomBubblingEventTypeConstants() noexcept; - winrt::Microsoft::ReactNative::ConstantProviderDelegate ExportedCustomDirectEventTypeConstants() noexcept; - - - // IViewManagerWithCommands - winrt::Windows::Foundation::Collections::IVectorView Commands() noexcept; - - void DispatchCommand( - winrt::Windows::UI::Xaml::FrameworkElement const &view, - winrt::hstring const &commandId, - winrt::Microsoft::ReactNative::IJSValueReader const &commandArgsReader) noexcept; - - private: - winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr }; - }; -} + +class ScreenContainerViewManager + : public winrt::implements< + ScreenContainerViewManager, + winrt::Microsoft::ReactNative::IViewManager, + winrt::Microsoft::ReactNative::IViewManagerRequiresNativeLayout, + winrt::Microsoft::ReactNative::IViewManagerWithChildren, + winrt::Microsoft::ReactNative::IViewManagerWithReactContext, + winrt::Microsoft::ReactNative::IViewManagerWithNativeProperties, + winrt::Microsoft::ReactNative:: + IViewManagerWithExportedEventTypeConstants, + winrt::Microsoft::ReactNative::IViewManagerWithCommands> { + public: + ScreenContainerViewManager() = default; + + // IViewManager + winrt::hstring Name() noexcept; + winrt::Windows::UI::Xaml::FrameworkElement CreateView() noexcept; + + // IViewManagerRequiresNativeLayout + bool RequiresNativeLayout(); + + // IViewManagerWithChildren + void AddView( + winrt::Windows::UI::Xaml::FrameworkElement parent, + winrt::Windows::UI::Xaml::UIElement child, + int64_t index); + void RemoveAllChildren(winrt::Windows::UI::Xaml::FrameworkElement parent); + void RemoveChildAt( + winrt::Windows::UI::Xaml::FrameworkElement parent, + int64_t index); + void ReplaceChild( + winrt::Windows::UI::Xaml::FrameworkElement parent, + winrt::Windows::UI::Xaml::UIElement oldChild, + winrt::Windows::UI::Xaml::UIElement newChild); + + // IViewManagerWithReactContext + winrt::Microsoft::ReactNative::IReactContext ReactContext() noexcept; + void ReactContext( + winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept; + + // IViewManagerWithNativeProperties + winrt::Windows::Foundation::Collections::IMapView< + winrt::hstring, + winrt::Microsoft::ReactNative::ViewManagerPropertyType> + NativeProps() noexcept; + + void UpdateProperties( + winrt::Windows::UI::Xaml::FrameworkElement const &view, + winrt::Microsoft::ReactNative::IJSValueReader const + &propertyMapReader) noexcept; + + // IViewManagerWithExportedEventTypeConstants + winrt::Microsoft::ReactNative::ConstantProviderDelegate + ExportedCustomBubblingEventTypeConstants() noexcept; + winrt::Microsoft::ReactNative::ConstantProviderDelegate + ExportedCustomDirectEventTypeConstants() noexcept; + + // IViewManagerWithCommands + winrt::Windows::Foundation::Collections::IVectorView + Commands() noexcept; + + void DispatchCommand( + winrt::Windows::UI::Xaml::FrameworkElement const &view, + winrt::hstring const &commandId, + winrt::Microsoft::ReactNative::IJSValueReader const + &commandArgsReader) noexcept; + + private: + winrt::Microsoft::ReactNative::IReactContext m_reactContext{nullptr}; +}; +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenStack.cpp b/windows/RNScreens/ScreenStack.cpp index a7957311a8..6dcfffd9a5 100644 --- a/windows/RNScreens/ScreenStack.cpp +++ b/windows/RNScreens/ScreenStack.cpp @@ -1,47 +1,49 @@ -#include "pch.h" -#include "NativeModules.h" -#include "JSValueXaml.h" #include "ScreenStack.h" +#include "JSValueXaml.h" +#include "NativeModules.h" +#include "pch.h" namespace winrt { - using namespace Microsoft::ReactNative; - using namespace Windows::Foundation; - using namespace Windows::Foundation::Collections; - using namespace Windows::UI; - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; -} +using namespace Microsoft::ReactNative; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +} // namespace winrt namespace winrt::RNScreens::implementation { - ScreenStack::ScreenStack(winrt::Microsoft::ReactNative::IReactContext reactContext) - : m_reactContext(reactContext), - m_children({ winrt::single_threaded_vector() }) { - } - - void ScreenStack::addScreen(Screen& screen, int64_t) { - auto uiElement = screen.try_as(); - if (!uiElement) - return; - - m_children.Append(uiElement); - Content(uiElement); - } - - void ScreenStack::removeAllChildren() { - Content(nullptr); - m_children.Clear(); - } - - void ScreenStack::removeChildAt(int64_t index) { - m_children.RemoveAt(static_cast(index)); - } - - void ScreenStack::replaceChild(winrt::Windows::UI::Xaml::UIElement oldChild, - winrt::Windows::UI::Xaml::UIElement newChild) { - uint32_t index; - if (!m_children.IndexOf(oldChild, index)) - return; - - m_children.SetAt(index, newChild); - } +ScreenStack::ScreenStack( + winrt::Microsoft::ReactNative::IReactContext reactContext) + : m_reactContext(reactContext), + m_children( + {winrt::single_threaded_vector()}) {} + +void ScreenStack::addScreen(Screen &screen, int64_t) { + auto uiElement = screen.try_as(); + if (!uiElement) + return; + + m_children.Append(uiElement); + Content(uiElement); +} + +void ScreenStack::removeAllChildren() { + Content(nullptr); + m_children.Clear(); +} + +void ScreenStack::removeChildAt(int64_t index) { + m_children.RemoveAt(static_cast(index)); +} + +void ScreenStack::replaceChild( + winrt::Windows::UI::Xaml::UIElement oldChild, + winrt::Windows::UI::Xaml::UIElement newChild) { + uint32_t index; + if (!m_children.IndexOf(oldChild, index)) + return; + + m_children.SetAt(index, newChild); } +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenStack.h b/windows/RNScreens/ScreenStack.h index ccbb458045..c1979581bd 100644 --- a/windows/RNScreens/ScreenStack.h +++ b/windows/RNScreens/ScreenStack.h @@ -2,18 +2,21 @@ #include "Screen.h" namespace winrt::RNScreens::implementation { - class ScreenStack : public winrt::Windows::UI::Xaml::Controls::ContentControlT { - public: - ScreenStack(winrt::Microsoft::ReactNative::IReactContext reactContext); - void addScreen(Screen& screen, int64_t index); - void removeAllChildren(); - void removeChildAt(int64_t index); - void replaceChild(winrt::Windows::UI::Xaml::UIElement oldChild, - winrt::Windows::UI::Xaml::UIElement newChild); +class ScreenStack + : public winrt::Windows::UI::Xaml::Controls::ContentControlT { + public: + ScreenStack(winrt::Microsoft::ReactNative::IReactContext reactContext); + void addScreen(Screen &screen, int64_t index); + void removeAllChildren(); + void removeChildAt(int64_t index); + void replaceChild( + winrt::Windows::UI::Xaml::UIElement oldChild, + winrt::Windows::UI::Xaml::UIElement newChild); - winrt::Windows::Foundation::Collections::IVector m_children; + winrt::Windows::Foundation::Collections::IVector + m_children; - private: - winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr }; - }; -} + private: + winrt::Microsoft::ReactNative::IReactContext m_reactContext{nullptr}; +}; +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenStackHeaderConfig.cpp b/windows/RNScreens/ScreenStackHeaderConfig.cpp index 332ae304e9..a57572a354 100644 --- a/windows/RNScreens/ScreenStackHeaderConfig.cpp +++ b/windows/RNScreens/ScreenStackHeaderConfig.cpp @@ -1,20 +1,19 @@ -#include "pch.h" -#include "NativeModules.h" -#include "JSValueXaml.h" #include "ScreenStackHeaderConfig.h" +#include "JSValueXaml.h" +#include "NativeModules.h" +#include "pch.h" namespace winrt { - using namespace Microsoft::ReactNative; - using namespace Windows::Foundation; - using namespace Windows::Foundation::Collections; - using namespace Windows::UI; - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; -} +using namespace Microsoft::ReactNative; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +} // namespace winrt namespace winrt::RNScreens::implementation { - ScreenStackHeaderConfig::ScreenStackHeaderConfig(winrt::Microsoft::ReactNative::IReactContext reactContext) - : m_reactContext(reactContext) { - - } -} +ScreenStackHeaderConfig::ScreenStackHeaderConfig( + winrt::Microsoft::ReactNative::IReactContext reactContext) + : m_reactContext(reactContext) {} +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenStackHeaderConfig.h b/windows/RNScreens/ScreenStackHeaderConfig.h index 96492cd60e..39fab151ce 100644 --- a/windows/RNScreens/ScreenStackHeaderConfig.h +++ b/windows/RNScreens/ScreenStackHeaderConfig.h @@ -1,11 +1,14 @@ #pragma once namespace winrt::RNScreens::implementation { - class ScreenStackHeaderConfig : public winrt::Windows::UI::Xaml::Controls::StackPanelT { - public: - ScreenStackHeaderConfig(winrt::Microsoft::ReactNative::IReactContext m_reactContext); +class ScreenStackHeaderConfig + : public winrt::Windows::UI::Xaml::Controls::StackPanelT< + ScreenStackHeaderConfig> { + public: + ScreenStackHeaderConfig( + winrt::Microsoft::ReactNative::IReactContext m_reactContext); - private: - winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr }; - }; - } + private: + winrt::Microsoft::ReactNative::IReactContext m_reactContext{nullptr}; +}; +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenStackHeaderConfigViewManager.cpp b/windows/RNScreens/ScreenStackHeaderConfigViewManager.cpp index 9656cc771f..2d1c435438 100644 --- a/windows/RNScreens/ScreenStackHeaderConfigViewManager.cpp +++ b/windows/RNScreens/ScreenStackHeaderConfigViewManager.cpp @@ -1,82 +1,89 @@ -#include "pch.h" -#include "NativeModules.h" -#include "JSValueXaml.h" #include "ScreenStackHeaderConfigViewManager.h" +#include "JSValueXaml.h" +#include "NativeModules.h" #include "ScreenStackHeaderConfig.h" +#include "pch.h" namespace winrt { - using namespace Microsoft::ReactNative; - using namespace Windows::Foundation; - using namespace Windows::Foundation::Collections; - using namespace Windows::UI; - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; -} +using namespace Microsoft::ReactNative; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +} // namespace winrt namespace winrt::RNScreens::implementation { - // IViewManager - winrt::hstring ScreenStackHeaderConfigViewManager::Name() noexcept { - return L"RNSScreenStackHeaderConfig"; - } +// IViewManager +winrt::hstring ScreenStackHeaderConfigViewManager::Name() noexcept { + return L"RNSScreenStackHeaderConfig"; +} - winrt::FrameworkElement ScreenStackHeaderConfigViewManager::CreateView() noexcept { - return winrt::make(m_reactContext); - } +winrt::FrameworkElement +ScreenStackHeaderConfigViewManager::CreateView() noexcept { + return winrt::make(m_reactContext); +} - // IViewManagerRequiresNativeLayout - bool ScreenStackHeaderConfigViewManager::RequiresNativeLayout() { - return true; - } +// IViewManagerRequiresNativeLayout +bool ScreenStackHeaderConfigViewManager::RequiresNativeLayout() { + return true; +} - // IViewManagerWithReactContext - winrt::IReactContext ScreenStackHeaderConfigViewManager::ReactContext() noexcept { - return m_reactContext; - } +// IViewManagerWithReactContext +winrt::IReactContext +ScreenStackHeaderConfigViewManager::ReactContext() noexcept { + return m_reactContext; +} - void ScreenStackHeaderConfigViewManager::ReactContext(IReactContext reactContext) noexcept { - m_reactContext = reactContext; - } +void ScreenStackHeaderConfigViewManager::ReactContext( + IReactContext reactContext) noexcept { + m_reactContext = reactContext; +} - // IViewManagerWithNativeProperties - IMapView ScreenStackHeaderConfigViewManager::NativeProps() noexcept { - auto nativeProps = winrt::single_threaded_map(); - return nativeProps.GetView(); - } +// IViewManagerWithNativeProperties +IMapView +ScreenStackHeaderConfigViewManager::NativeProps() noexcept { + auto nativeProps = + winrt::single_threaded_map(); + return nativeProps.GetView(); +} - void ScreenStackHeaderConfigViewManager::UpdateProperties( - FrameworkElement const& view, - IJSValueReader const& propertyMapReader) noexcept { - (void)view; - const JSValueObject& propertyMap = JSValue::ReadObjectFrom(propertyMapReader); - for (auto const& pair : propertyMap) { - auto const& propertyName = pair.first; - auto const& propertyValue = pair.second; - (void)propertyName; - (void)propertyValue; - } - } +void ScreenStackHeaderConfigViewManager::UpdateProperties( + FrameworkElement const &view, + IJSValueReader const &propertyMapReader) noexcept { + (void)view; + const JSValueObject &propertyMap = JSValue::ReadObjectFrom(propertyMapReader); + for (auto const &pair : propertyMap) { + auto const &propertyName = pair.first; + auto const &propertyValue = pair.second; + (void)propertyName; + (void)propertyValue; + } +} - // IViewManagerWithExportedEventTypeConstants - ConstantProviderDelegate ScreenStackHeaderConfigViewManager::ExportedCustomBubblingEventTypeConstants() noexcept { - return nullptr; - } +// IViewManagerWithExportedEventTypeConstants +ConstantProviderDelegate ScreenStackHeaderConfigViewManager:: + ExportedCustomBubblingEventTypeConstants() noexcept { + return nullptr; +} - ConstantProviderDelegate ScreenStackHeaderConfigViewManager::ExportedCustomDirectEventTypeConstants() noexcept { - return nullptr; - } +ConstantProviderDelegate ScreenStackHeaderConfigViewManager:: + ExportedCustomDirectEventTypeConstants() noexcept { + return nullptr; +} - // IViewManagerWithCommands - IVectorView ScreenStackHeaderConfigViewManager::Commands() noexcept { - auto commands = winrt::single_threaded_vector(); - return commands.GetView(); - } +// IViewManagerWithCommands +IVectorView ScreenStackHeaderConfigViewManager::Commands() noexcept { + auto commands = winrt::single_threaded_vector(); + return commands.GetView(); +} - void ScreenStackHeaderConfigViewManager::DispatchCommand( - FrameworkElement const& view, - winrt::hstring const& commandId, - winrt::IJSValueReader const& commandArgsReader) noexcept { - (void)view; - (void)commandId; - (void)commandArgsReader; - } +void ScreenStackHeaderConfigViewManager::DispatchCommand( + FrameworkElement const &view, + winrt::hstring const &commandId, + winrt::IJSValueReader const &commandArgsReader) noexcept { + (void)view; + (void)commandId; + (void)commandArgsReader; } +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenStackHeaderConfigViewManager.h b/windows/RNScreens/ScreenStackHeaderConfigViewManager.h index 7c39fe269c..ed37a80b93 100644 --- a/windows/RNScreens/ScreenStackHeaderConfigViewManager.h +++ b/windows/RNScreens/ScreenStackHeaderConfigViewManager.h @@ -1,54 +1,62 @@ #pragma once -#include "winrt/Microsoft.ReactNative.h" #include "NativeModules.h" - +#include "winrt/Microsoft.ReactNative.h" namespace winrt::RNScreens::implementation { - - class ScreenStackHeaderConfigViewManager : public winrt::implements< - ScreenStackHeaderConfigViewManager, - winrt::Microsoft::ReactNative::IViewManager, - winrt::Microsoft::ReactNative::IViewManagerRequiresNativeLayout, - winrt::Microsoft::ReactNative::IViewManagerWithReactContext, - winrt::Microsoft::ReactNative::IViewManagerWithNativeProperties, - winrt::Microsoft::ReactNative::IViewManagerWithExportedEventTypeConstants, - winrt::Microsoft::ReactNative::IViewManagerWithCommands> { - public: - ScreenStackHeaderConfigViewManager() = default; - - // IViewManager - winrt::hstring Name() noexcept; - winrt::Windows::UI::Xaml::FrameworkElement CreateView() noexcept; - - // IViewManagerRequiresNativeLayout - bool RequiresNativeLayout(); - - // IViewManagerWithReactContext - winrt::Microsoft::ReactNative::IReactContext ReactContext() noexcept; - void ReactContext(winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept; - - // IViewManagerWithNativeProperties - winrt::Windows::Foundation::Collections:: - IMapView - NativeProps() noexcept; - - void UpdateProperties( - winrt::Windows::UI::Xaml::FrameworkElement const& view, - winrt::Microsoft::ReactNative::IJSValueReader const& propertyMapReader) noexcept; - - // IViewManagerWithExportedEventTypeConstants - winrt::Microsoft::ReactNative::ConstantProviderDelegate ExportedCustomBubblingEventTypeConstants() noexcept; - winrt::Microsoft::ReactNative::ConstantProviderDelegate ExportedCustomDirectEventTypeConstants() noexcept; - - // IViewManagerWithCommands - winrt::Windows::Foundation::Collections::IVectorView Commands() noexcept; - - void DispatchCommand( - winrt::Windows::UI::Xaml::FrameworkElement const &view, - winrt::hstring const &commandId, - winrt::Microsoft::ReactNative::IJSValueReader const &commandArgsReader) noexcept; - - private: - winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr }; - }; -} + +class ScreenStackHeaderConfigViewManager + : public winrt::implements< + ScreenStackHeaderConfigViewManager, + winrt::Microsoft::ReactNative::IViewManager, + winrt::Microsoft::ReactNative::IViewManagerRequiresNativeLayout, + winrt::Microsoft::ReactNative::IViewManagerWithReactContext, + winrt::Microsoft::ReactNative::IViewManagerWithNativeProperties, + winrt::Microsoft::ReactNative:: + IViewManagerWithExportedEventTypeConstants, + winrt::Microsoft::ReactNative::IViewManagerWithCommands> { + public: + ScreenStackHeaderConfigViewManager() = default; + + // IViewManager + winrt::hstring Name() noexcept; + winrt::Windows::UI::Xaml::FrameworkElement CreateView() noexcept; + + // IViewManagerRequiresNativeLayout + bool RequiresNativeLayout(); + + // IViewManagerWithReactContext + winrt::Microsoft::ReactNative::IReactContext ReactContext() noexcept; + void ReactContext( + winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept; + + // IViewManagerWithNativeProperties + winrt::Windows::Foundation::Collections::IMapView< + winrt::hstring, + winrt::Microsoft::ReactNative::ViewManagerPropertyType> + NativeProps() noexcept; + + void UpdateProperties( + winrt::Windows::UI::Xaml::FrameworkElement const &view, + winrt::Microsoft::ReactNative::IJSValueReader const + &propertyMapReader) noexcept; + + // IViewManagerWithExportedEventTypeConstants + winrt::Microsoft::ReactNative::ConstantProviderDelegate + ExportedCustomBubblingEventTypeConstants() noexcept; + winrt::Microsoft::ReactNative::ConstantProviderDelegate + ExportedCustomDirectEventTypeConstants() noexcept; + + // IViewManagerWithCommands + winrt::Windows::Foundation::Collections::IVectorView + Commands() noexcept; + + void DispatchCommand( + winrt::Windows::UI::Xaml::FrameworkElement const &view, + winrt::hstring const &commandId, + winrt::Microsoft::ReactNative::IJSValueReader const + &commandArgsReader) noexcept; + + private: + winrt::Microsoft::ReactNative::IReactContext m_reactContext{nullptr}; +}; +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenStackViewManager.cpp b/windows/RNScreens/ScreenStackViewManager.cpp index af33905e36..078ce96e7d 100644 --- a/windows/RNScreens/ScreenStackViewManager.cpp +++ b/windows/RNScreens/ScreenStackViewManager.cpp @@ -1,120 +1,132 @@ -#include "pch.h" -#include "NativeModules.h" -#include "JSValueXaml.h" #include "ScreenStackViewManager.h" -#include "ScreenStack.h" +#include "JSValueXaml.h" +#include "NativeModules.h" #include "Screen.h" +#include "ScreenStack.h" +#include "pch.h" namespace winrt { - using namespace Microsoft::ReactNative; - using namespace Windows::Foundation; - using namespace Windows::Foundation::Collections; - using namespace Windows::UI; - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; -} +using namespace Microsoft::ReactNative; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +} // namespace winrt namespace winrt::RNScreens::implementation { - // IViewManager - winrt::hstring ScreenStackViewManager::Name() noexcept { - return L"RNSScreenStack"; - } - - winrt::FrameworkElement ScreenStackViewManager::CreateView() noexcept { - return winrt::make(m_reactContext); - } - - // IViewManagerRequiresNativeLayout - bool ScreenStackViewManager::RequiresNativeLayout() { - return false; - } - - // IViewManagerWithChildren - void ScreenStackViewManager::AddView(FrameworkElement parent, UIElement child, int64_t index) { - auto screenStack = parent.as(); - if (!screenStack) - return; - - auto screen = child.as(); - if (!screen) - return; - - screenStack->addScreen(*screen, index); - } - - void ScreenStackViewManager::RemoveAllChildren(FrameworkElement parent) { - auto screenStack = parent.as(); - if (!screenStack) - return; - - screenStack->removeAllChildren(); - } - - void ScreenStackViewManager::RemoveChildAt(FrameworkElement parent, int64_t index) { - auto screenStack = parent.as(); - if (!screenStack) - return; - - screenStack->removeChildAt(index); - } - - void ScreenStackViewManager::ReplaceChild(FrameworkElement parent, UIElement oldChild, UIElement newChild) { - auto screenStack = parent.as(); - if (!screenStack) - return; - - screenStack->replaceChild(oldChild, newChild); - } - - // IViewManagerWithReactContext - winrt::IReactContext ScreenStackViewManager::ReactContext() noexcept { - return m_reactContext; - } - - void ScreenStackViewManager::ReactContext(IReactContext reactContext) noexcept { - m_reactContext = reactContext; - } - - // IViewManagerWithNativeProperties - IMapView ScreenStackViewManager::NativeProps() noexcept { - auto nativeProps = winrt::single_threaded_map(); - return nativeProps.GetView(); - } - - void ScreenStackViewManager::UpdateProperties( - FrameworkElement const& view, - IJSValueReader const& propertyMapReader) noexcept { - (void)view; - const JSValueObject& propertyMap = JSValue::ReadObjectFrom(propertyMapReader); - for (auto const& pair : propertyMap) { - auto const& propertyName = pair.first; - auto const& propertyValue = pair.second; - (void)propertyName; - (void)propertyValue; - } - } - - // IViewManagerWithExportedEventTypeConstants - ConstantProviderDelegate ScreenStackViewManager::ExportedCustomBubblingEventTypeConstants() noexcept { - return nullptr; - } - - ConstantProviderDelegate ScreenStackViewManager::ExportedCustomDirectEventTypeConstants() noexcept { - return nullptr; - } - - // IViewManagerWithCommands - IVectorView ScreenStackViewManager::Commands() noexcept { - auto commands = winrt::single_threaded_vector(); - return commands.GetView(); - } - - void ScreenStackViewManager::DispatchCommand( - FrameworkElement const& view, - winrt::hstring const& commandId, - winrt::IJSValueReader const& commandArgsReader) noexcept { - (void)view; - (void)commandId; - (void)commandArgsReader; - } +// IViewManager +winrt::hstring ScreenStackViewManager::Name() noexcept { + return L"RNSScreenStack"; +} + +winrt::FrameworkElement ScreenStackViewManager::CreateView() noexcept { + return winrt::make(m_reactContext); +} + +// IViewManagerRequiresNativeLayout +bool ScreenStackViewManager::RequiresNativeLayout() { + return false; +} + +// IViewManagerWithChildren +void ScreenStackViewManager::AddView( + FrameworkElement parent, + UIElement child, + int64_t index) { + auto screenStack = parent.as(); + if (!screenStack) + return; + + auto screen = child.as(); + if (!screen) + return; + + screenStack->addScreen(*screen, index); +} + +void ScreenStackViewManager::RemoveAllChildren(FrameworkElement parent) { + auto screenStack = parent.as(); + if (!screenStack) + return; + + screenStack->removeAllChildren(); +} + +void ScreenStackViewManager::RemoveChildAt( + FrameworkElement parent, + int64_t index) { + auto screenStack = parent.as(); + if (!screenStack) + return; + + screenStack->removeChildAt(index); +} + +void ScreenStackViewManager::ReplaceChild( + FrameworkElement parent, + UIElement oldChild, + UIElement newChild) { + auto screenStack = parent.as(); + if (!screenStack) + return; + + screenStack->replaceChild(oldChild, newChild); +} + +// IViewManagerWithReactContext +winrt::IReactContext ScreenStackViewManager::ReactContext() noexcept { + return m_reactContext; +} + +void ScreenStackViewManager::ReactContext(IReactContext reactContext) noexcept { + m_reactContext = reactContext; +} + +// IViewManagerWithNativeProperties +IMapView +ScreenStackViewManager::NativeProps() noexcept { + auto nativeProps = + winrt::single_threaded_map(); + return nativeProps.GetView(); +} + +void ScreenStackViewManager::UpdateProperties( + FrameworkElement const &view, + IJSValueReader const &propertyMapReader) noexcept { + (void)view; + const JSValueObject &propertyMap = JSValue::ReadObjectFrom(propertyMapReader); + for (auto const &pair : propertyMap) { + auto const &propertyName = pair.first; + auto const &propertyValue = pair.second; + (void)propertyName; + (void)propertyValue; + } +} + +// IViewManagerWithExportedEventTypeConstants +ConstantProviderDelegate +ScreenStackViewManager::ExportedCustomBubblingEventTypeConstants() noexcept { + return nullptr; +} + +ConstantProviderDelegate +ScreenStackViewManager::ExportedCustomDirectEventTypeConstants() noexcept { + return nullptr; +} + +// IViewManagerWithCommands +IVectorView ScreenStackViewManager::Commands() noexcept { + auto commands = winrt::single_threaded_vector(); + return commands.GetView(); +} + +void ScreenStackViewManager::DispatchCommand( + FrameworkElement const &view, + winrt::hstring const &commandId, + winrt::IJSValueReader const &commandArgsReader) noexcept { + (void)view; + (void)commandId; + (void)commandArgsReader; } +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenStackViewManager.h b/windows/RNScreens/ScreenStackViewManager.h index bb699c8f63..812ea1b236 100644 --- a/windows/RNScreens/ScreenStackViewManager.h +++ b/windows/RNScreens/ScreenStackViewManager.h @@ -1,62 +1,78 @@ #pragma once -#include "winrt/Microsoft.ReactNative.h" #include "NativeModules.h" +#include "winrt/Microsoft.ReactNative.h" namespace winrt::RNScreens::implementation { - - class ScreenStackViewManager : public winrt::implements< - ScreenStackViewManager, - winrt::Microsoft::ReactNative::IViewManager, - winrt::Microsoft::ReactNative::IViewManagerRequiresNativeLayout, - winrt::Microsoft::ReactNative::IViewManagerWithChildren, - winrt::Microsoft::ReactNative::IViewManagerWithReactContext, - winrt::Microsoft::ReactNative::IViewManagerWithNativeProperties, - winrt::Microsoft::ReactNative::IViewManagerWithExportedEventTypeConstants, - winrt::Microsoft::ReactNative::IViewManagerWithCommands> { - public: - ScreenStackViewManager() = default; - - // IViewManager - winrt::hstring Name() noexcept; - winrt::Windows::UI::Xaml::FrameworkElement CreateView() noexcept; - - // IViewManagerRequiresNativeLayout - bool RequiresNativeLayout(); - - // IViewManagerWithChildren - void AddView(winrt::Windows::UI::Xaml::FrameworkElement parent, winrt::Windows::UI::Xaml::UIElement child, int64_t index); - void RemoveAllChildren(winrt::Windows::UI::Xaml::FrameworkElement parent); - void RemoveChildAt(winrt::Windows::UI::Xaml::FrameworkElement parent, int64_t index); - void ReplaceChild(winrt::Windows::UI::Xaml::FrameworkElement parent, winrt::Windows::UI::Xaml::UIElement oldChild, winrt::Windows::UI::Xaml::UIElement newChild); - - // IViewManagerWithReactContext - winrt::Microsoft::ReactNative::IReactContext ReactContext() noexcept; - void ReactContext(winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept; - - // IViewManagerWithNativeProperties - winrt::Windows::Foundation::Collections:: - IMapView - NativeProps() noexcept; - - void UpdateProperties( - winrt::Windows::UI::Xaml::FrameworkElement const& view, - winrt::Microsoft::ReactNative::IJSValueReader const& propertyMapReader) noexcept; - - // IViewManagerWithExportedEventTypeConstants - winrt::Microsoft::ReactNative::ConstantProviderDelegate ExportedCustomBubblingEventTypeConstants() noexcept; - winrt::Microsoft::ReactNative::ConstantProviderDelegate ExportedCustomDirectEventTypeConstants() noexcept; - - - // IViewManagerWithCommands - winrt::Windows::Foundation::Collections::IVectorView Commands() noexcept; - - void DispatchCommand( - winrt::Windows::UI::Xaml::FrameworkElement const &view, - winrt::hstring const &commandId, - winrt::Microsoft::ReactNative::IJSValueReader const &commandArgsReader) noexcept; - - private: - winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr }; - }; -} + +class ScreenStackViewManager + : public winrt::implements< + ScreenStackViewManager, + winrt::Microsoft::ReactNative::IViewManager, + winrt::Microsoft::ReactNative::IViewManagerRequiresNativeLayout, + winrt::Microsoft::ReactNative::IViewManagerWithChildren, + winrt::Microsoft::ReactNative::IViewManagerWithReactContext, + winrt::Microsoft::ReactNative::IViewManagerWithNativeProperties, + winrt::Microsoft::ReactNative:: + IViewManagerWithExportedEventTypeConstants, + winrt::Microsoft::ReactNative::IViewManagerWithCommands> { + public: + ScreenStackViewManager() = default; + + // IViewManager + winrt::hstring Name() noexcept; + winrt::Windows::UI::Xaml::FrameworkElement CreateView() noexcept; + + // IViewManagerRequiresNativeLayout + bool RequiresNativeLayout(); + + // IViewManagerWithChildren + void AddView( + winrt::Windows::UI::Xaml::FrameworkElement parent, + winrt::Windows::UI::Xaml::UIElement child, + int64_t index); + void RemoveAllChildren(winrt::Windows::UI::Xaml::FrameworkElement parent); + void RemoveChildAt( + winrt::Windows::UI::Xaml::FrameworkElement parent, + int64_t index); + void ReplaceChild( + winrt::Windows::UI::Xaml::FrameworkElement parent, + winrt::Windows::UI::Xaml::UIElement oldChild, + winrt::Windows::UI::Xaml::UIElement newChild); + + // IViewManagerWithReactContext + winrt::Microsoft::ReactNative::IReactContext ReactContext() noexcept; + void ReactContext( + winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept; + + // IViewManagerWithNativeProperties + winrt::Windows::Foundation::Collections::IMapView< + winrt::hstring, + winrt::Microsoft::ReactNative::ViewManagerPropertyType> + NativeProps() noexcept; + + void UpdateProperties( + winrt::Windows::UI::Xaml::FrameworkElement const &view, + winrt::Microsoft::ReactNative::IJSValueReader const + &propertyMapReader) noexcept; + + // IViewManagerWithExportedEventTypeConstants + winrt::Microsoft::ReactNative::ConstantProviderDelegate + ExportedCustomBubblingEventTypeConstants() noexcept; + winrt::Microsoft::ReactNative::ConstantProviderDelegate + ExportedCustomDirectEventTypeConstants() noexcept; + + // IViewManagerWithCommands + winrt::Windows::Foundation::Collections::IVectorView + Commands() noexcept; + + void DispatchCommand( + winrt::Windows::UI::Xaml::FrameworkElement const &view, + winrt::hstring const &commandId, + winrt::Microsoft::ReactNative::IJSValueReader const + &commandArgsReader) noexcept; + + private: + winrt::Microsoft::ReactNative::IReactContext m_reactContext{nullptr}; +}; +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenViewManager.cpp b/windows/RNScreens/ScreenViewManager.cpp index 084d9ede96..08eaa56b1f 100644 --- a/windows/RNScreens/ScreenViewManager.cpp +++ b/windows/RNScreens/ScreenViewManager.cpp @@ -1,144 +1,154 @@ -#include "pch.h" -#include "NativeModules.h" -#include "JSValueXaml.h" #include "ScreenViewManager.h" +#include "JSValueXaml.h" +#include "NativeModules.h" #include "Screen.h" +#include "pch.h" namespace winrt { - using namespace Microsoft::ReactNative; - using namespace Windows::Foundation; - using namespace Windows::Foundation::Collections; - using namespace Windows::UI; - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; -} +using namespace Microsoft::ReactNative; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +} // namespace winrt namespace winrt::RNScreens::implementation { - // IViewManager - winrt::hstring ScreenViewManager::Name() noexcept { - return L"RNSScreen"; - } - - winrt::FrameworkElement ScreenViewManager::CreateView() noexcept { - return winrt::make(m_reactContext); - } +// IViewManager +winrt::hstring ScreenViewManager::Name() noexcept { + return L"RNSScreen"; +} - // IViewManagerRequiresNativeLayout - bool ScreenViewManager::RequiresNativeLayout() { - return false; - } +winrt::FrameworkElement ScreenViewManager::CreateView() noexcept { + return winrt::make(m_reactContext); +} - // IViewManagerWithChildren - void ScreenViewManager::AddView(FrameworkElement parent, UIElement child, int64_t index) { - (void)index; - auto screen = parent.try_as(); - if (!screen) - return; +// IViewManagerRequiresNativeLayout +bool ScreenViewManager::RequiresNativeLayout() { + return false; +} - screen->addView(child); - } +// IViewManagerWithChildren +void ScreenViewManager::AddView( + FrameworkElement parent, + UIElement child, + int64_t index) { + (void)index; + auto screen = parent.try_as(); + if (!screen) + return; + + screen->addView(child); +} - void ScreenViewManager::RemoveAllChildren(FrameworkElement parent) { - auto screen = parent.try_as(); - if (!screen) - return; +void ScreenViewManager::RemoveAllChildren(FrameworkElement parent) { + auto screen = parent.try_as(); + if (!screen) + return; - screen->removeAllChildren(); - } + screen->removeAllChildren(); +} - void ScreenViewManager::RemoveChildAt(FrameworkElement parent, int64_t index) { - auto screen = parent.try_as(); - if (!screen) - return; +void ScreenViewManager::RemoveChildAt(FrameworkElement parent, int64_t index) { + auto screen = parent.try_as(); + if (!screen) + return; - screen->removeChildAt(index); - } + screen->removeChildAt(index); +} - void ScreenViewManager::ReplaceChild(FrameworkElement parent, UIElement oldChild, UIElement newChild) { - auto screen = parent.try_as(); - if (!screen) - return; +void ScreenViewManager::ReplaceChild( + FrameworkElement parent, + UIElement oldChild, + UIElement newChild) { + auto screen = parent.try_as(); + if (!screen) + return; - screen->replaceChild(oldChild, newChild); - } + screen->replaceChild(oldChild, newChild); +} - // IViewManagerWithReactContext - winrt::IReactContext ScreenViewManager::ReactContext() noexcept { - return m_reactContext; - } +// IViewManagerWithReactContext +winrt::IReactContext ScreenViewManager::ReactContext() noexcept { + return m_reactContext; +} - void ScreenViewManager::ReactContext(IReactContext reactContext) noexcept { - m_reactContext = reactContext; - } +void ScreenViewManager::ReactContext(IReactContext reactContext) noexcept { + m_reactContext = reactContext; +} - // IViewManagerWithNativeProperties - IMapView ScreenViewManager::NativeProps() noexcept { - auto nativeProps = winrt::single_threaded_map(); - nativeProps.Insert(L"stackPresentation", ViewManagerPropertyType::String); - nativeProps.Insert(L"stackAnimation", ViewManagerPropertyType::String); - nativeProps.Insert(L"gestureEnabled", ViewManagerPropertyType::Boolean); - nativeProps.Insert(L"replaceAnimation", ViewManagerPropertyType::String); - nativeProps.Insert(L"screenOrientation", ViewManagerPropertyType::String); - nativeProps.Insert(L"statusBarAnimation", ViewManagerPropertyType::String); - nativeProps.Insert(L"statusBarColor", ViewManagerPropertyType::Number); - nativeProps.Insert(L"statusBarStyle", ViewManagerPropertyType::String); - nativeProps.Insert(L"statusBarTranslucent", ViewManagerPropertyType::Boolean); - nativeProps.Insert(L"statusBarHidden", ViewManagerPropertyType::Boolean); - return nativeProps.GetView(); - } +// IViewManagerWithNativeProperties +IMapView +ScreenViewManager::NativeProps() noexcept { + auto nativeProps = + winrt::single_threaded_map(); + nativeProps.Insert(L"stackPresentation", ViewManagerPropertyType::String); + nativeProps.Insert(L"stackAnimation", ViewManagerPropertyType::String); + nativeProps.Insert(L"gestureEnabled", ViewManagerPropertyType::Boolean); + nativeProps.Insert(L"replaceAnimation", ViewManagerPropertyType::String); + nativeProps.Insert(L"screenOrientation", ViewManagerPropertyType::String); + nativeProps.Insert(L"statusBarAnimation", ViewManagerPropertyType::String); + nativeProps.Insert(L"statusBarColor", ViewManagerPropertyType::Number); + nativeProps.Insert(L"statusBarStyle", ViewManagerPropertyType::String); + nativeProps.Insert(L"statusBarTranslucent", ViewManagerPropertyType::Boolean); + nativeProps.Insert(L"statusBarHidden", ViewManagerPropertyType::Boolean); + return nativeProps.GetView(); +} - void ScreenViewManager::UpdateProperties( - FrameworkElement const& view, - IJSValueReader const& propertyMapReader) noexcept { - (void)view; - const JSValueObject& propertyMap = JSValue::ReadObjectFrom(propertyMapReader); - for (auto const& pair : propertyMap) { - auto const& propertyName = pair.first; - auto const& propertyValue = pair.second; - if (propertyValue != nullptr) { - if (propertyName == "replaceAnimation") { - auto const& value = propertyValue.AsString(); - // TODO: Implement this for Windows - (void)value; - } else if (propertyName == "stackPresentation") { - auto const& value = propertyValue.AsString(); - // TODO: Implement this for Windows - (void)value; - } else { - OutputDebugStringA("Unknown property in ScreenViewManager\n"); - } - } - } +void ScreenViewManager::UpdateProperties( + FrameworkElement const &view, + IJSValueReader const &propertyMapReader) noexcept { + (void)view; + const JSValueObject &propertyMap = JSValue::ReadObjectFrom(propertyMapReader); + for (auto const &pair : propertyMap) { + auto const &propertyName = pair.first; + auto const &propertyValue = pair.second; + if (propertyValue != nullptr) { + if (propertyName == "replaceAnimation") { + auto const &value = propertyValue.AsString(); + // TODO: Implement this for Windows + (void)value; + } else if (propertyName == "stackPresentation") { + auto const &value = propertyValue.AsString(); + // TODO: Implement this for Windows + (void)value; + } else { + OutputDebugStringA("Unknown property in ScreenViewManager\n"); + } } + } +} - // IViewManagerWithExportedEventTypeConstants - ConstantProviderDelegate ScreenViewManager::ExportedCustomBubblingEventTypeConstants() noexcept { - return nullptr; - } +// IViewManagerWithExportedEventTypeConstants +ConstantProviderDelegate +ScreenViewManager::ExportedCustomBubblingEventTypeConstants() noexcept { + return nullptr; +} - ConstantProviderDelegate ScreenViewManager::ExportedCustomDirectEventTypeConstants() noexcept { - return [](winrt::IJSValueWriter const& constantWriter) { - WriteCustomDirectEventTypeConstant(constantWriter, "WillAppear"); - WriteCustomDirectEventTypeConstant(constantWriter, "WillDisappear"); - WriteCustomDirectEventTypeConstant(constantWriter, "Appear"); - WriteCustomDirectEventTypeConstant(constantWriter, "Disappear"); - WriteCustomDirectEventTypeConstant(constantWriter, "Dismissed"); - WriteCustomDirectEventTypeConstant(constantWriter, "FinishTransitioning"); - }; - } +ConstantProviderDelegate +ScreenViewManager::ExportedCustomDirectEventTypeConstants() noexcept { + return [](winrt::IJSValueWriter const &constantWriter) { + WriteCustomDirectEventTypeConstant(constantWriter, "WillAppear"); + WriteCustomDirectEventTypeConstant(constantWriter, "WillDisappear"); + WriteCustomDirectEventTypeConstant(constantWriter, "Appear"); + WriteCustomDirectEventTypeConstant(constantWriter, "Disappear"); + WriteCustomDirectEventTypeConstant(constantWriter, "Dismissed"); + WriteCustomDirectEventTypeConstant(constantWriter, "FinishTransitioning"); + }; +} - // IViewManagerWithCommands - IVectorView ScreenViewManager::Commands() noexcept { - auto commands = winrt::single_threaded_vector(); - return commands.GetView(); - } +// IViewManagerWithCommands +IVectorView ScreenViewManager::Commands() noexcept { + auto commands = winrt::single_threaded_vector(); + return commands.GetView(); +} - void ScreenViewManager::DispatchCommand( - FrameworkElement const& view, - winrt::hstring const& commandId, - winrt::IJSValueReader const& commandArgsReader) noexcept { - (void)view; - (void)commandId; - (void)commandArgsReader; - } +void ScreenViewManager::DispatchCommand( + FrameworkElement const &view, + winrt::hstring const &commandId, + winrt::IJSValueReader const &commandArgsReader) noexcept { + (void)view; + (void)commandId; + (void)commandArgsReader; } +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/ScreenViewManager.h b/windows/RNScreens/ScreenViewManager.h index 90b71608f2..17cb8e1bf9 100644 --- a/windows/RNScreens/ScreenViewManager.h +++ b/windows/RNScreens/ScreenViewManager.h @@ -1,61 +1,78 @@ #pragma once -#include "winrt/Microsoft.ReactNative.h" #include "NativeModules.h" +#include "winrt/Microsoft.ReactNative.h" namespace winrt::RNScreens::implementation { - - class ScreenViewManager : public winrt::implements< - ScreenViewManager, - winrt::Microsoft::ReactNative::IViewManager, - winrt::Microsoft::ReactNative::IViewManagerRequiresNativeLayout, - winrt::Microsoft::ReactNative::IViewManagerWithChildren, - winrt::Microsoft::ReactNative::IViewManagerWithReactContext, - winrt::Microsoft::ReactNative::IViewManagerWithNativeProperties, - winrt::Microsoft::ReactNative::IViewManagerWithExportedEventTypeConstants, - winrt::Microsoft::ReactNative::IViewManagerWithCommands> { - public: - ScreenViewManager() = default; - - // IViewManager - winrt::hstring Name() noexcept; - winrt::Windows::UI::Xaml::FrameworkElement CreateView() noexcept; - - // IViewManagerRequiresNativeLayout - bool RequiresNativeLayout(); - - // IViewManagerWithChildren - void AddView(winrt::Windows::UI::Xaml::FrameworkElement parent, winrt::Windows::UI::Xaml::UIElement child, int64_t index); - void RemoveAllChildren(winrt::Windows::UI::Xaml::FrameworkElement parent); - void RemoveChildAt(winrt::Windows::UI::Xaml::FrameworkElement parent, int64_t index); - void ReplaceChild(winrt::Windows::UI::Xaml::FrameworkElement parent, winrt::Windows::UI::Xaml::UIElement oldChild, winrt::Windows::UI::Xaml::UIElement newChild); - - // IViewManagerWithReactContext - winrt::Microsoft::ReactNative::IReactContext ReactContext() noexcept; - void ReactContext(winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept; - - // IViewManagerWithNativeProperties - winrt::Windows::Foundation::Collections:: - IMapView - NativeProps() noexcept; - - void UpdateProperties( - winrt::Windows::UI::Xaml::FrameworkElement const& view, - winrt::Microsoft::ReactNative::IJSValueReader const& propertyMapReader) noexcept; - - // IViewManagerWithExportedEventTypeConstants - winrt::Microsoft::ReactNative::ConstantProviderDelegate ExportedCustomBubblingEventTypeConstants() noexcept; - winrt::Microsoft::ReactNative::ConstantProviderDelegate ExportedCustomDirectEventTypeConstants() noexcept; - - // IViewManagerWithCommands - winrt::Windows::Foundation::Collections::IVectorView Commands() noexcept; - - void DispatchCommand( - winrt::Windows::UI::Xaml::FrameworkElement const &view, - winrt::hstring const &commandId, - winrt::Microsoft::ReactNative::IJSValueReader const &commandArgsReader) noexcept; - - private: - winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr }; - }; -} + +class ScreenViewManager + : public winrt::implements< + ScreenViewManager, + winrt::Microsoft::ReactNative::IViewManager, + winrt::Microsoft::ReactNative::IViewManagerRequiresNativeLayout, + winrt::Microsoft::ReactNative::IViewManagerWithChildren, + winrt::Microsoft::ReactNative::IViewManagerWithReactContext, + winrt::Microsoft::ReactNative::IViewManagerWithNativeProperties, + winrt::Microsoft::ReactNative:: + IViewManagerWithExportedEventTypeConstants, + winrt::Microsoft::ReactNative::IViewManagerWithCommands> { + public: + ScreenViewManager() = default; + + // IViewManager + winrt::hstring Name() noexcept; + winrt::Windows::UI::Xaml::FrameworkElement CreateView() noexcept; + + // IViewManagerRequiresNativeLayout + bool RequiresNativeLayout(); + + // IViewManagerWithChildren + void AddView( + winrt::Windows::UI::Xaml::FrameworkElement parent, + winrt::Windows::UI::Xaml::UIElement child, + int64_t index); + void RemoveAllChildren(winrt::Windows::UI::Xaml::FrameworkElement parent); + void RemoveChildAt( + winrt::Windows::UI::Xaml::FrameworkElement parent, + int64_t index); + void ReplaceChild( + winrt::Windows::UI::Xaml::FrameworkElement parent, + winrt::Windows::UI::Xaml::UIElement oldChild, + winrt::Windows::UI::Xaml::UIElement newChild); + + // IViewManagerWithReactContext + winrt::Microsoft::ReactNative::IReactContext ReactContext() noexcept; + void ReactContext( + winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept; + + // IViewManagerWithNativeProperties + winrt::Windows::Foundation::Collections::IMapView< + winrt::hstring, + winrt::Microsoft::ReactNative::ViewManagerPropertyType> + NativeProps() noexcept; + + void UpdateProperties( + winrt::Windows::UI::Xaml::FrameworkElement const &view, + winrt::Microsoft::ReactNative::IJSValueReader const + &propertyMapReader) noexcept; + + // IViewManagerWithExportedEventTypeConstants + winrt::Microsoft::ReactNative::ConstantProviderDelegate + ExportedCustomBubblingEventTypeConstants() noexcept; + winrt::Microsoft::ReactNative::ConstantProviderDelegate + ExportedCustomDirectEventTypeConstants() noexcept; + + // IViewManagerWithCommands + winrt::Windows::Foundation::Collections::IVectorView + Commands() noexcept; + + void DispatchCommand( + winrt::Windows::UI::Xaml::FrameworkElement const &view, + winrt::hstring const &commandId, + winrt::Microsoft::ReactNative::IJSValueReader const + &commandArgsReader) noexcept; + + private: + winrt::Microsoft::ReactNative::IReactContext m_reactContext{nullptr}; +}; +} // namespace winrt::RNScreens::implementation diff --git a/windows/RNScreens/pch.h b/windows/RNScreens/pch.h index d3584d41d0..6754588bae 100644 --- a/windows/RNScreens/pch.h +++ b/windows/RNScreens/pch.h @@ -1,9 +1,9 @@ #pragma once #include -#include +#include #include +#include #include -#include #include -#include \ No newline at end of file +#include \ No newline at end of file