Skip to content

Commit

Permalink
Add ModalScreenViewManager and ScreenStackHeaderSubview to Windows Na…
Browse files Browse the repository at this point in the history
…tive UI Components
  • Loading branch information
adrianryt committed Aug 26, 2024
1 parent 77df570 commit 64a9e79
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 2 deletions.
23 changes: 23 additions & 0 deletions windows/RNScreens/ModalScreenViewManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "pch.h"
#include "ModalScreenViewManager.h"
#include "JSValueXaml.h"
#include "NativeModules.h"
#include "ModalScreen.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;
} // namespace winrt

namespace winrt::RNScreens::implementation {
// IViewManager
winrt::hstring ModalScreenViewManager::Name() noexcept {
return L"RNSModalScreen";
}


} // namespace winrt::RNScreens::implementation
13 changes: 13 additions & 0 deletions windows/RNScreens/ModalScreenViewManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include "NativeModules.h"
#include "winrt/Microsoft.ReactNative.h"
#include "ScreenViewManager.h"

namespace winrt::RNScreens::implementation {

class ModalScreenViewManager : public ScreenViewManager {
public:
ModalScreenViewManager() = default;
virtual winrt::hstring Name() noexcept;
};
} // namespace winrt::RNScreens::implementation
6 changes: 6 additions & 0 deletions windows/RNScreens/RNScreens.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
<ClInclude Include="ScreenContainerViewManager.h" />
<ClInclude Include="ScreenStack.h" />
<ClInclude Include="ScreenStackHeaderConfigViewManager.h" />
<ClInclude Include="ScreenStackHeaderSubviewViewManager.h" />
<ClInclude Include="ModalScreenViewManager.h" />
<ClInclude Include="ScreenViewManager.h" />
<ClInclude Include="RNScreens.h">
<DependentUpon>RNScreens.idl</DependentUpon>
Expand All @@ -133,6 +135,7 @@
<DependentUpon>RNScreens.idl</DependentUpon>
</ClCompile>
<ClInclude Include="ScreenStackHeaderConfig.h" />
<ClInclude Include="ScreenStackHeaderSubview.h" />
<ClInclude Include="ScreenStackViewManager.h" />
</ItemGroup>
<ItemGroup>
Expand All @@ -144,12 +147,15 @@
<ClCompile Include="ScreenContainerViewManager.cpp" />
<ClCompile Include="ScreenStack.cpp" />
<ClCompile Include="ScreenStackHeaderConfigViewManager.cpp" />
<ClCompile Include="ScreenStackHeaderSubviewViewManager.cpp" />
<ClCompile Include="ModalScreenViewManager.cpp" />
<ClCompile Include="ScreenViewManager.cpp" />
<ClCompile Include="ReactPackageProvider.cpp">
<DependentUpon>ReactPackageProvider.idl</DependentUpon>
</ClCompile>
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="ScreenStackHeaderConfig.cpp" />
<ClCompile Include="ScreenStackHeaderSubview.cpp" />
<ClCompile Include="ScreenStackViewManager.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions windows/RNScreens/RNScreens.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
<ClCompile Include="RNScreens.cpp" />
<ClCompile Include="Screen.cpp" />
<ClCompile Include="ScreenStackHeaderConfigViewManager.cpp" />
<ClCompile Include="ScreenStackHeaderSubviewViewManager.cpp" />
<ClCompile Include="ModalScreenViewManager.cpp" />
<ClCompile Include="ScreenViewManager.cpp" />
<ClCompile Include="ScreenStackHeaderConfig.cpp" />
<ClCompile Include="ScreenStackHeaderSubview.cpp" />
<ClCompile Include="ScreenStackViewManager.cpp" />
<ClCompile Include="ScreenStack.cpp" />
<ClCompile Include="ScreenContainerViewManager.cpp" />
Expand All @@ -31,8 +34,11 @@
<ClInclude Include="RNScreens.h" />
<ClInclude Include="Screen.h" />
<ClInclude Include="ScreenStackHeaderConfigViewManager.h" />
<ClInclude Include="ScreenStackHeaderSubviewViewManager.h" />
<ClInclude Include="ModalScreenViewManager.h" />
<ClInclude Include="ScreenViewManager.h" />
<ClInclude Include="ScreenStackHeaderConfig.h" />
<ClInclude Include="ScreenStackHeaderSubview.h" />
<ClInclude Include="ScreenStackViewManager.h" />
<ClInclude Include="ScreenStack.h" />
<ClInclude Include="ScreenContainer.h" />
Expand Down
13 changes: 13 additions & 0 deletions windows/RNScreens/ReactPackageProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "ScreenStackHeaderConfigViewManager.h"
#include "ScreenStackViewManager.h"
#include "ScreenViewManager.h"
#include "ScreenStackHeaderSubviewViewManager.h"
#include "ModalScreenViewManager.h"

using namespace winrt::Microsoft::ReactNative;

Expand All @@ -17,14 +19,25 @@ void ReactPackageProvider::CreatePackage(
packageBuilder.AddViewManager(L"RNScreensViewManager", []() {
return winrt::make<ScreenViewManager>();
});

packageBuilder.AddViewManager(L"RNScreensStackHeaderConfigViewManager", []() {
return winrt::make<ScreenStackHeaderConfigViewManager>();
});

packageBuilder.AddViewManager(L"RNSScreenStackViewManager", []() {
return winrt::make<ScreenStackViewManager>();
});

packageBuilder.AddViewManager(L"RNSScreenContainerViewManager", []() {
return winrt::make<ScreenContainerViewManager>();
});

packageBuilder.AddViewManager(L"RNSScreenStackHeaderSubviewViewManager", [] () {
return winrt::make<ScreenStackHeaderSubviewViewManager>();
});

packageBuilder.AddViewManager(L"RNSModalScreenViewManager", [] () {
return winrt::make<ModalScreenViewManager>();
});
}
} // namespace winrt::RNScreens::implementation
2 changes: 1 addition & 1 deletion windows/RNScreens/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace winrt::RNScreens::implementation {

enum class StackPresentation { PUSH, MODAL, TRANSPARENT_MODAL };
enum class StackPresentation { PUSH, MODAL, TRANSPARENT_MODAL, FORM_SHEET };

enum class StackAnimation {
DEFAULT,
Expand Down
19 changes: 19 additions & 0 deletions windows/RNScreens/ScreenStackHeaderSubview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "pch.h"
#include "ScreenStackHeaderSubview.h"
#include "JSValueXaml.h"
#include "NativeModules.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;
} // namespace winrt

namespace winrt::RNScreens::implementation {
ScreenStackHeaderSubview::ScreenStackHeaderSubview(
winrt::Microsoft::ReactNative::IReactContext reactContext)
: m_reactContext(reactContext) {}
} // namespace winrt::RNScreens::implementation
14 changes: 14 additions & 0 deletions windows/RNScreens/ScreenStackHeaderSubview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace winrt::RNScreens::implementation {
class ScreenStackHeaderSubview
: public winrt::Windows::UI::Xaml::Controls::StackPanelT<
ScreenStackHeaderSubview> {
public:
ScreenStackHeaderSubview(
winrt::Microsoft::ReactNative::IReactContext m_reactContext);

private:
winrt::Microsoft::ReactNative::IReactContext m_reactContext{nullptr};
};
} // namespace winrt::RNScreens::implementation
89 changes: 89 additions & 0 deletions windows/RNScreens/ScreenStackHeaderSubviewViewManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "pch.h"
#include "ScreenStackHeaderSubviewViewManager.h"
#include "JSValueXaml.h"
#include "NativeModules.h"
#include "ScreenStackHeaderSubview.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;
} // namespace winrt

namespace winrt::RNScreens::implementation {
// IViewManager
winrt::hstring ScreenStackHeaderSubviewViewManager::Name() noexcept {
return L"RNSScreenStackHeaderSubview";
}

winrt::FrameworkElement
ScreenStackHeaderSubviewViewManager::CreateView() noexcept {
return winrt::make<ScreenStackHeaderSubview>(m_reactContext);
}

// IViewManagerRequiresNativeLayout
bool ScreenStackHeaderSubviewViewManager::RequiresNativeLayout() {
return true;
}

// IViewManagerWithReactContext
winrt::IReactContext
ScreenStackHeaderSubviewViewManager::ReactContext() noexcept {
return m_reactContext;
}

void ScreenStackHeaderSubviewViewManager::ReactContext(
IReactContext reactContext) noexcept {
m_reactContext = reactContext;
}

// IViewManagerWithNativeProperties
IMapView<hstring, ViewManagerPropertyType>
ScreenStackHeaderSubviewViewManager::NativeProps() noexcept {
auto nativeProps =
winrt::single_threaded_map<hstring, ViewManagerPropertyType>();
return nativeProps.GetView();
}

void ScreenStackHeaderSubviewViewManager::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 ScreenStackHeaderSubviewViewManager::
ExportedCustomBubblingEventTypeConstants() noexcept {
return nullptr;
}

ConstantProviderDelegate ScreenStackHeaderSubviewViewManager::
ExportedCustomDirectEventTypeConstants() noexcept {
return nullptr;
}

// IViewManagerWithCommands
IVectorView<hstring> ScreenStackHeaderSubviewViewManager::Commands() noexcept {
auto commands = winrt::single_threaded_vector<hstring>();
return commands.GetView();
}

void ScreenStackHeaderSubviewViewManager::DispatchCommand(
FrameworkElement const &view,
winrt::hstring const &commandId,
winrt::IJSValueReader const &commandArgsReader) noexcept {
(void)view;
(void)commandId;
(void)commandArgsReader;
}
} // namespace winrt::RNScreens::implementation
62 changes: 62 additions & 0 deletions windows/RNScreens/ScreenStackHeaderSubviewViewManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once
#include "NativeModules.h"
#include "winrt/Microsoft.ReactNative.h"

namespace winrt::RNScreens::implementation {

class ScreenStackHeaderSubviewViewManager
: public winrt::implements<
ScreenStackHeaderSubviewViewManager,
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:
ScreenStackHeaderSubviewViewManager() = 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<winrt::hstring>
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
2 changes: 1 addition & 1 deletion windows/RNScreens/ScreenViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ScreenViewManager
ScreenViewManager() = default;

// IViewManager
winrt::hstring Name() noexcept;
virtual winrt::hstring Name() noexcept;
winrt::Windows::UI::Xaml::FrameworkElement CreateView() noexcept;

// IViewManagerRequiresNativeLayout
Expand Down

0 comments on commit 64a9e79

Please sign in to comment.