Skip to content

Commit

Permalink
Add new UI components, add StackAnimation property to Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianryt committed Sep 23, 2024
1 parent 64a9e79 commit ec5e88a
Show file tree
Hide file tree
Showing 22 changed files with 596 additions and 183 deletions.
4 changes: 3 additions & 1 deletion src/components/ScreenContentWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Platform, View, ViewProps } from 'react-native';
import ScreenContentWrapperNativeComponent from '../fabric/ScreenContentWrapperNativeComponent';

export const NativeScreenContentWrapper: React.ComponentType<ViewProps> =
Platform.OS !== 'web' ? (ScreenContentWrapperNativeComponent as any) : View;
Platform.OS !== 'web' && Platform.OS !== 'windows'
? (ScreenContentWrapperNativeComponent as any)

Check warning on line 7 in src/components/ScreenContentWrapper.tsx

View workflow job for this annotation

GitHub Actions / install-and-lint

Unexpected any. Specify a different type
: View;

function ScreenContentWrapper(props: ViewProps) {
return <NativeScreenContentWrapper collapsable={false} {...props} />;
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BackHandler, Platform } from 'react-native';
export const isSearchBarAvailableForCurrentPlatform = [
'ios',
'android',
'windows'
].includes(Platform.OS);

export function executeNativeBackPress() {
Expand Down
1 change: 0 additions & 1 deletion windows/RNScreens/ModalScreenViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "ModalScreenViewManager.h"
#include "JSValueXaml.h"
#include "NativeModules.h"
#include "ModalScreen.h"

namespace winrt {
using namespace Microsoft::ReactNative;
Expand Down
2 changes: 1 addition & 1 deletion windows/RNScreens/ModalScreenViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace winrt::RNScreens::implementation {
class ModalScreenViewManager : public ScreenViewManager {
public:
ModalScreenViewManager() = default;
virtual winrt::hstring Name() noexcept;
winrt::hstring Name() noexcept;
};
} // namespace winrt::RNScreens::implementation
4 changes: 4 additions & 0 deletions windows/RNScreens/RNScreens.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<ClInclude Include="ScreenStack.h" />
<ClInclude Include="ScreenStackHeaderConfigViewManager.h" />
<ClInclude Include="ScreenStackHeaderSubviewViewManager.h" />
<ClInclude Include="SearchBarViewManager.h" />
<ClInclude Include="ModalScreenViewManager.h" />
<ClInclude Include="ScreenViewManager.h" />
<ClInclude Include="RNScreens.h">
Expand All @@ -136,6 +137,7 @@
</ClCompile>
<ClInclude Include="ScreenStackHeaderConfig.h" />
<ClInclude Include="ScreenStackHeaderSubview.h" />
<ClInclude Include="SearchBar.h" />
<ClInclude Include="ScreenStackViewManager.h" />
</ItemGroup>
<ItemGroup>
Expand All @@ -148,6 +150,7 @@
<ClCompile Include="ScreenStack.cpp" />
<ClCompile Include="ScreenStackHeaderConfigViewManager.cpp" />
<ClCompile Include="ScreenStackHeaderSubviewViewManager.cpp" />
<ClCompile Include="SearchBarViewManager.cpp" />
<ClCompile Include="ModalScreenViewManager.cpp" />
<ClCompile Include="ScreenViewManager.cpp" />
<ClCompile Include="ReactPackageProvider.cpp">
Expand All @@ -156,6 +159,7 @@
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="ScreenStackHeaderConfig.cpp" />
<ClCompile Include="ScreenStackHeaderSubview.cpp" />
<ClCompile Include="SearchBar.cpp" />
<ClCompile Include="ScreenStackViewManager.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions windows/RNScreens/RNScreens.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
<ClCompile Include="Screen.cpp" />
<ClCompile Include="ScreenStackHeaderConfigViewManager.cpp" />
<ClCompile Include="ScreenStackHeaderSubviewViewManager.cpp" />
<ClCompile Include="SearchBarViewManager.cpp" />
<ClCompile Include="ModalScreenViewManager.cpp" />
<ClCompile Include="ScreenViewManager.cpp" />
<ClCompile Include="ScreenStackHeaderConfig.cpp" />
<ClCompile Include="ScreenStackHeaderSubview.cpp" />
<ClCompile Include="SearchBar.cpp" />
<ClCompile Include="ScreenStackViewManager.cpp" />
<ClCompile Include="ScreenStack.cpp" />
<ClCompile Include="ScreenContainerViewManager.cpp" />
Expand All @@ -35,10 +37,12 @@
<ClInclude Include="Screen.h" />
<ClInclude Include="ScreenStackHeaderConfigViewManager.h" />
<ClInclude Include="ScreenStackHeaderSubviewViewManager.h" />
<ClInclude Include="SearchBarViewManager.h" />
<ClInclude Include="ModalScreenViewManager.h" />
<ClInclude Include="ScreenViewManager.h" />
<ClInclude Include="ScreenStackHeaderConfig.h" />
<ClInclude Include="ScreenStackHeaderSubview.h" />
<ClInclude Include="SearchBar.h" />
<ClInclude Include="ScreenStackViewManager.h" />
<ClInclude Include="ScreenStack.h" />
<ClInclude Include="ScreenContainer.h" />
Expand Down
5 changes: 5 additions & 0 deletions windows/RNScreens/ReactPackageProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ScreenViewManager.h"
#include "ScreenStackHeaderSubviewViewManager.h"
#include "ModalScreenViewManager.h"
#include "SearchBarViewManager.h"

using namespace winrt::Microsoft::ReactNative;

Expand Down Expand Up @@ -39,5 +40,9 @@ void ReactPackageProvider::CreatePackage(
packageBuilder.AddViewManager(L"RNSModalScreenViewManager", [] () {
return winrt::make<ModalScreenViewManager>();
});

packageBuilder.AddViewManager(L"RNSSearchBar", [] () {
return winrt::make<SearchBarViewManager>();
});
}
} // namespace winrt::RNScreens::implementation
250 changes: 128 additions & 122 deletions windows/RNScreens/Screen.cpp
Original file line number Diff line number Diff line change
@@ -1,122 +1,128 @@
#include "pch.h"
#include "Screen.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 {
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<uint32_t>(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<Screen>();
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<Screen>();
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<Screen>();
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
#include "pch.h"
#include "Screen.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 {
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<uint32_t>(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<Screen>();
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<Screen>();
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<Screen>();
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();
});
}
StackAnimation Screen::GetStackAnimation() const {
return stackAnimation;
}
void Screen::SetStackAnimation(StackAnimation const& animation) {
stackAnimation = animation;
}
} // namespace winrt::RNScreens::implementation
6 changes: 5 additions & 1 deletion windows/RNScreens/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ enum class StackAnimation {
DEFAULT,
NONE,
FADE,
SIMPLE_FROM_BOTTOM,
SLIDE_FROM_BOTTOM,
SLIDE_FROM_RIGHT,
SLIDE_FROM_LEFT,
FADE_FROM_BOTTOM,
IOS
};

Expand Down Expand Up @@ -58,8 +59,11 @@ class Screen : public winrt::Windows::UI::Xaml::Controls::StackPanelT<Screen> {
void dispatchOnDisappear();
void dispatchOnWillAppear();
void dispatchOnWillDisappear();
StackAnimation GetStackAnimation() const;
void SetStackAnimation(StackAnimation const& animation);

private:
winrt::Microsoft::ReactNative::IReactContext m_reactContext{nullptr};
StackAnimation stackAnimation;
};
} // namespace winrt::RNScreens::implementation
Loading

0 comments on commit ec5e88a

Please sign in to comment.