Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Implelent Shared StatusBarManagerModule and Do Module Cleanup",
"packageName": "@office-iss/react-native-win32",
"email": "ngerlem@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-04-15T12:17:45.965Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Implelent Shared StatusBarManagerModule and Do Module Cleanup",
"packageName": "react-native-windows",
"email": "ngerlem@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-04-15T12:17:49.517Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export interface Spec extends TurboModule {
+setHidden: (hidden: boolean) => void;
}

// [Win32 Change from getEnforcing to get and provide a stub (See #4363)
// [Win32 Change from getEnforcing to get and provide a stub (See #4363). This
// can be removed once devmain integrates with 0.62 native bits.
let NativeStausBarManager = TurboModuleRegistry.get<Spec>('StatusBarManager');
if (!NativeStausBarManager) {
NativeStausBarManager = {
Expand Down
25 changes: 0 additions & 25 deletions vnext/Desktop.IntegrationTests/DesktopTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,6 @@ using std::vector;

namespace Microsoft::React::Test {

class StubNativeModule : public facebook::xplat::module::CxxModule {
public:
StubNativeModule(std::string name) : m_name(std::move(name)) {}

std::string getName() override {
return m_name;
}

std::map<std::string, folly::dynamic> getConstants() override {
// CxxModules require a constant or method to register properly
return {{"Dummy", "Something"}};
}

std::vector<Method> getMethods() override {
return {};
}

private:
std::string m_name;
};

shared_ptr<ITestInstance> TestRunner::GetInstance(
string &&jsBundleFile,
vector<tuple<string, CxxModule::Provider>> &&cxxModules,
Expand Down Expand Up @@ -94,10 +73,6 @@ shared_ptr<ITestInstance> TestRunner::GetInstance(
make_tuple(
TestDeviceInfoModule::name,
[]() -> unique_ptr<CxxModule> { return make_unique<TestDeviceInfoModule>(); },
nativeQueue),
make_tuple(
"StatusBarManager",
[]() -> unique_ptr<CxxModule> { return make_unique<StubNativeModule>("StatusBarManager"); },
nativeQueue)};

// <0> string
Expand Down
2 changes: 0 additions & 2 deletions vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@
<ClInclude Include="..\ReactUWP\Modules\LocationObserverModule.h" />
<ClInclude Include="..\ReactUWP\Modules\NativeUIManager.h" />
<ClInclude Include="..\ReactUWP\Modules\NetworkingModule.h" />
<ClInclude Include="..\ReactUWP\Modules\StatusBarModule.h" />
<ClInclude Include="..\ReactUWP\Modules\TimingModule.h" />
<ClInclude Include="..\ReactUWP\Modules\WebSocketModuleUwp.h" />
<ClInclude Include="..\ReactUWP\Polyester\ButtonContentViewManager.h" />
Expand Down Expand Up @@ -378,7 +377,6 @@
<ClCompile Include="..\ReactUWP\Modules\LocationObserverModule.cpp" />
<ClCompile Include="..\ReactUWP\Modules\NativeUIManager.cpp" />
<ClCompile Include="..\ReactUWP\Modules\NetworkingModule.cpp" />
<ClCompile Include="..\ReactUWP\Modules\StatusBarModule.cpp" />
<ClCompile Include="..\ReactUWP\Modules\TimingModule.cpp" />
<ClCompile Include="..\ReactUWP\Modules\WebSocketModuleUwp.cpp" />
<ClCompile Include="..\ReactUWP\Polyester\ButtonContentViewManager.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@
<ClCompile Include="..\ReactUWP\Modules\NetworkingModule.cpp">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="..\ReactUWP\Modules\StatusBarModule.cpp">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="..\ReactUWP\Modules\TimingModule.cpp">
<Filter>Modules</Filter>
</ClCompile>
Expand Down Expand Up @@ -434,9 +431,6 @@
<ClInclude Include="..\ReactUWP\Modules\NetworkingModule.h">
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="..\ReactUWP\Modules\StatusBarModule.h">
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="..\ReactUWP\Modules\TimingModule.h">
<Filter>Modules</Filter>
</ClInclude>
Expand Down
3 changes: 1 addition & 2 deletions vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ void ReactInstanceWin::Initialize() noexcept {
m_uiManager.Load(),
m_batchingUIThread,
m_uiMessageThread.Load(),
m_deviceInfo,
devSettings,
std::move(m_deviceInfo),
std::move(m_i18nInfo),
std::move(m_appState),
std::move(m_appTheme),
Expand Down
2 changes: 1 addition & 1 deletion vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class ReactInstanceWin final : public Mso::ActiveObject<IReactInstanceInternal,
std::shared_ptr<react::uwp::DeviceInfo> m_deviceInfo;
std::shared_ptr<facebook::react::AppState> m_appState;
std::shared_ptr<IRedBoxHandler> m_redboxHandler;
std::shared_ptr<react::windows::AppTheme> m_appTheme;
std::shared_ptr<react::uwp::AppTheme> m_appTheme;
std::pair<std::string, bool> m_i18nInfo{};
std::string m_bundleRootPath;
};
Expand Down
20 changes: 8 additions & 12 deletions vnext/ReactUWP/Base/CoreNativeModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <Modules/LocationObserverModule.h>
#include <Modules/NativeUIManager.h>
#include <Modules/NetworkingModule.h>
#include <Modules/StatusBarModule.h>
#include <Modules/UIManagerModule.h>
#include <Modules/WebSocketModuleUwp.h>
#include <ReactUWP/Modules/I18nModule.h>
Expand Down Expand Up @@ -49,21 +48,20 @@ bool HasPackageIdentity() noexcept {
} // namespace

std::vector<facebook::react::NativeModuleDescription> GetCoreModules(
std::shared_ptr<facebook::react::IUIManager> uiManager,
const std::shared_ptr<facebook::react::IUIManager> &uiManager,
const std::shared_ptr<facebook::react::MessageQueueThread> &messageQueue,
const std::shared_ptr<facebook::react::MessageQueueThread> &uiMessageQueue,
std::shared_ptr<DeviceInfo> deviceInfo,
std::shared_ptr<facebook::react::DevSettings> devSettings,
const I18nModule::I18nInfo &&i18nInfo,
std::shared_ptr<facebook::react::AppState> appstate,
std::shared_ptr<react::windows::AppTheme> appTheme,
std::shared_ptr<DeviceInfo> &&deviceInfo,
I18nModule::I18nInfo &&i18nInfo,
std::shared_ptr<facebook::react::AppState> &&appstate,
std::shared_ptr<react::uwp::AppTheme> &&appTheme,
const std::shared_ptr<IReactInstance> &uwpInstance) noexcept {
// Modules
std::vector<facebook::react::NativeModuleDescription> modules;

modules.emplace_back(
"UIManager",
[uiManager = std::move(uiManager), uiMessageQueue]() {
[uiManager, uiMessageQueue]() {
return facebook::react::createUIManagerModule(std::shared_ptr(uiManager), std::shared_ptr(uiMessageQueue));
},
messageQueue);
Expand Down Expand Up @@ -103,18 +101,16 @@ std::vector<facebook::react::NativeModuleDescription> GetCoreModules(
MakeSerialQueueThread());

modules.emplace_back(
react::windows::AppThemeModule::name,
react::uwp::AppThemeModule::Name,
[appTheme = std::move(appTheme)]() mutable {
return std::make_unique<react::windows::AppThemeModule>(std::move(appTheme));
return std::make_unique<react::uwp::AppThemeModule>(std::move(appTheme));
},
messageQueue);

modules.emplace_back(AlertModule::name, []() { return std::make_unique<AlertModule>(); }, messageQueue);

modules.emplace_back(ClipboardModule::name, []() { return std::make_unique<ClipboardModule>(); }, messageQueue);

modules.emplace_back(StatusBarModule::name, []() { return std::make_unique<StatusBarModule>(); }, messageQueue);

modules.emplace_back(
NativeAnimatedModule::name,
[wpUwpInstance = std::weak_ptr(uwpInstance)]() mutable {
Expand Down
13 changes: 6 additions & 7 deletions vnext/ReactUWP/Base/CoreNativeModules.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include <Modules/AppThemeModule.h>
#include <ReactUWP/Modules/AppThemeModuleUwp.h>
#include <ReactUWP/Modules/I18nModule.h>
#include <ReactWindowsCore/NativeModuleProvider.h>
#include <memory>
Expand All @@ -23,14 +23,13 @@ struct IReactInstance;
struct ViewManagerProvider;

std::vector<facebook::react::NativeModuleDescription> GetCoreModules(
std::shared_ptr<facebook::react::IUIManager> uiManager,
const std::shared_ptr<facebook::react::IUIManager> &uiManager,
const std::shared_ptr<facebook::react::MessageQueueThread> &messageQueue,
const std::shared_ptr<facebook::react::MessageQueueThread> &uiMessageQueue,
std::shared_ptr<DeviceInfo> deviceInfo,
std::shared_ptr<facebook::react::DevSettings> devSettings,
const I18nModule::I18nInfo &&i18nInfo,
std::shared_ptr<facebook::react::AppState> appstate,
std::shared_ptr<react::windows::AppTheme> appTheme,
std::shared_ptr<DeviceInfo> &&deviceInfo,
I18nModule::I18nInfo &&i18nInfo,
std::shared_ptr<facebook::react::AppState> &&appstate,
std::shared_ptr<react::uwp::AppTheme> &&appTheme,
const std::shared_ptr<IReactInstance> &uwpInstance) noexcept;

} // namespace react::uwp
5 changes: 2 additions & 3 deletions vnext/ReactUWP/Base/UwpReactInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void UwpReactInstance::Start(const std::shared_ptr<IReactInstance> &spThis, cons
// Objects that must be created on the UI thread
auto deviceInfo(std::make_shared<DeviceInfo>(spThis));
std::shared_ptr<facebook::react::AppState> appstate = std::make_shared<react::uwp::AppState>(spThis);
std::shared_ptr<react::windows::AppTheme> appTheme =
std::shared_ptr<react::uwp::AppTheme> appTheme =
std::make_shared<react::uwp::AppTheme>(spThis, m_defaultNativeThread);
std::pair<std::string, bool> i18nInfo = I18nModule::GetI18nInfo();

Expand Down Expand Up @@ -199,8 +199,7 @@ void UwpReactInstance::Start(const std::shared_ptr<IReactInstance> &spThis, cons
m_uiManager,
m_batchingNativeThread,
m_defaultNativeThread,
deviceInfo,
devSettings,
std::move(deviceInfo),
std::move(i18nInfo),
std::move(appstate),
std::move(appTheme),
Expand Down
27 changes: 18 additions & 9 deletions vnext/ReactUWP/Modules/AppThemeModuleUwp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ using namespace Windows::UI::Xaml;
using namespace Windows::UI::ViewManagement;
} // namespace winrt

namespace react {
namespace uwp {
namespace react::uwp {

//
// AppTheme
Expand All @@ -27,7 +26,7 @@ namespace uwp {
AppTheme::AppTheme(
const std::shared_ptr<IReactInstance> &reactInstance,
const std::shared_ptr<facebook::react::MessageQueueThread> &defaultQueueThread)
: react::windows::AppTheme(), m_wkReactInstance(reactInstance), m_queueThread(defaultQueueThread) {
: m_wkReactInstance(reactInstance), m_queueThread(defaultQueueThread) {
m_currentTheme = winrt::Application::Current().RequestedTheme();
m_isHighContrast = m_accessibilitySettings.HighContrast();
m_highContrastColors = getHighContrastColors();
Expand All @@ -53,10 +52,8 @@ AppTheme::AppTheme(
});
}

AppTheme::~AppTheme() = default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it removed? There are some advantages keeping default destructors in .cpp file. Especially if the default constructor has to clean up a lot of variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate a bit?


const std::string AppTheme::getCurrentTheme() {
return m_currentTheme == winrt::ApplicationTheme::Light ? AppTheme::light : AppTheme::dark;
std::string AppTheme::getCurrentTheme() {
return m_currentTheme == winrt::ApplicationTheme::Light ? AppTheme::Light : AppTheme::Dark;
}

bool AppTheme::getIsHighContrast() {
Expand Down Expand Up @@ -94,5 +91,17 @@ void AppTheme::fireEvent(std::string const &eventName, folly::dynamic &&eventDat
instance->CallJsFunction("RCTDeviceEventEmitter", "emit", folly::dynamic::array(eventName, std::move(eventData)));
}
}
} // namespace uwp
} // namespace react

AppThemeModule::AppThemeModule(std::shared_ptr<AppTheme> &&appTheme) : m_appTheme(std::move(appTheme)) {}

auto AppThemeModule::getConstants() -> std::map<std::string, folly::dynamic> {
return {{"initialAppTheme", folly::dynamic{m_appTheme->getCurrentTheme()}},
{"initialHighContrast", folly::dynamic{m_appTheme->getIsHighContrast()}},
{"initialHighContrastColors", folly::dynamic{m_appTheme->getHighContrastColors()}}};
}

auto AppThemeModule::getMethods() -> std::vector<facebook::xplat::module::CxxModule::Method> {
return {};
}

} // namespace react::uwp
38 changes: 27 additions & 11 deletions vnext/ReactUWP/Modules/AppThemeModuleUwp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
#pragma once

#include <IReactInstance.h>
#include <Modules/AppThemeModule.h>
#include <cxxreact/MessageQueueThread.h>
#include <winrt/Windows.UI.ViewManagement.h>

namespace react {
namespace uwp {
namespace react::uwp {

class AppTheme : public react::windows::AppTheme {
class AppTheme {
public:
static constexpr const char *Dark = "dark";
static constexpr const char *Light = "light";

AppTheme(
const std::shared_ptr<IReactInstance> &reactInstance,
const std::shared_ptr<facebook::react::MessageQueueThread> &defaultQueueThread);
virtual ~AppTheme();

const std::string getCurrentTheme() override;
bool getIsHighContrast() override;
std::string getCurrentTheme();
bool getIsHighContrast();
folly::dynamic getHighContrastColors();

private:
// High Contrast Color helper methods
folly::dynamic getHighContrastColors();
// High Contrast Color helper method
std::string formatRGB(winrt::Windows::UI::Color ElementColor);

void fireEvent(std::string const &eventName, folly::dynamic &&eventData);
Expand All @@ -40,5 +40,21 @@ class AppTheme : public react::windows::AppTheme {
winrt::Windows::UI::ViewManagement::UISettings::ColorValuesChanged_revoker m_colorValuesChangedRevoker{};
};

} // namespace uwp
} // namespace react
class AppThemeModule : public facebook::xplat::module::CxxModule {
public:
static constexpr const char *Name = "RTCAppTheme";

AppThemeModule(std::shared_ptr<AppTheme> &&appTheme);

// CxxModule
std::string getName() override {
return Name;
};
auto getConstants() -> std::map<std::string, folly::dynamic> override;
auto getMethods() -> std::vector<Method> override;

private:
std::shared_ptr<AppTheme> m_appTheme;
};

} // namespace react::uwp
31 changes: 0 additions & 31 deletions vnext/ReactUWP/Modules/StatusBarModule.cpp

This file was deleted.

25 changes: 0 additions & 25 deletions vnext/ReactUWP/Modules/StatusBarModule.h

This file was deleted.

Loading