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
8 changes: 8 additions & 0 deletions change/react-native-windows-2020-04-29-03-21-18-testhook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Refactor TestHook out of ViewManagerBase and special case layout properties",
"packageName": "react-native-windows",
"email": "asklar@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-04-29T10:21:18.921Z"
}
2 changes: 2 additions & 0 deletions vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
</ClInclude>
<ClInclude Include="RedBox.h" />
<ClInclude Include="ReactSupport.h" />
<ClInclude Include="TestHook.h" />
<ClInclude Include="Threading\BatchingQueueThread.h" />
<ClInclude Include="Threading\MessageDispatchQueue.h" />
<ClInclude Include="Threading\MessageQueueThreadFactory.h" />
Expand Down Expand Up @@ -488,6 +489,7 @@
</ClCompile>
<ClCompile Include="RedBox.cpp" />
<ClCompile Include="ReactSupport.cpp" />
<ClCompile Include="TestHook.cpp" />
<ClCompile Include="Threading\BatchingQueueThread.cpp" />
<ClCompile Include="Threading\MessageDispatchQueue.cpp" />
<ClCompile Include="Threading\MessageQueueThreadFactory.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@
<ClCompile Include="..\ReactUWP\Modules\AppThemeModuleUwp.cpp">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="..\ReactUWP\Modules\ClipboardModule.cpp">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="..\ReactUWP\Modules\DeviceInfoModule.cpp">
<Filter>Modules</Filter>
</ClCompile>
Expand Down Expand Up @@ -318,6 +315,8 @@
<ClCompile Include="Views\ReactRootControl.cpp">
<Filter>Views</Filter>
</ClCompile>
<ClCompile Include="Modules\ClipboardModule.cpp" />
<ClCompile Include="TestHook.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\ReactUWP\Base\CoreNativeModules.h">
Expand Down Expand Up @@ -410,9 +409,6 @@
<ClInclude Include="..\ReactUWP\Modules\AppThemeModuleUwp.h">
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="..\ReactUWP\Modules\ClipboardModule.h">
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="..\ReactUWP\Modules\DeviceInfoModule.h">
<Filter>Modules</Filter>
</ClInclude>
Expand Down Expand Up @@ -674,6 +670,8 @@
<ClInclude Include="Views\ReactRootControl.h">
<Filter>Views</Filter>
</ClInclude>
<ClInclude Include="Modules\ClipboardModule.h" />
<ClInclude Include="TestHook.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="..\ReactUWP\Views\cppwinrt\AccessibilityAction.idl">
Expand Down
103 changes: 103 additions & 0 deletions vnext/Microsoft.ReactNative/TestHook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "pch.h"
#include "TestHook.h"
#include <cdebug.h>

#ifdef DEBUG

// Obtained from https://reactnative.dev/docs/layout-props
// See getLayoutProps.ps1 next to this file.
std::vector<std::string> TestHook::layoutProperties = {
"alignContent",
"alignItems",
"alignSelf",
"aspectRatio",
"borderBottomWidth",
"borderEndWidth",
"borderLeftWidth",
"borderRightWidth",
"borderStartWidth",
"borderTopWidth",
"borderWidth",
"bottom",
"direction",
"display",
"end",
"flex",
"flexBasis",
"flexDirection",
"flexGrow",
"flexShrink",
"flexWrap",
"height",
"justifyContent",
"left",
"margin",
"marginBottom",
"marginEnd",
"marginHorizontal",
"marginLeft",
"marginRight",
"marginStart",
"marginTop",
"marginVertical",
"maxHeight",
"maxWidth",
"minHeight",
"minWidth",
"overflow",
"padding",
"paddingBottom",
"paddingEnd",
"paddingHorizontal",
"paddingLeft",
"paddingRight",
"paddingStart",
"paddingTop",
"paddingVertical",
"position",
"right",
"start",
"top",
"width",
"zIndex",
};

void TestHook::NotifyUnimplementedProperty(
const std::string &viewManager,
const std::string &reactClassName,
const std::string &propertyName,
const folly::dynamic &propertyValue) {
if (std::find(layoutProperties.begin(), layoutProperties.end(), propertyName) != layoutProperties.end()) {
return;
}
std::string value;
size_t size{};
try {
if (propertyValue.isObject()) {
value = "[Object]";
} else if (propertyValue.isNull()) {
value = "[Null]";
} else if (propertyValue.isArray()) {
size = propertyValue.size();
value = "[Array]";
} else {
value = propertyValue.asString();
}
} catch (const folly::TypeError &e) {
value = e.what();
}

cdebug << "[UnimplementedProperty] ViewManager = " << viewManager << " elementClass = " << reactClassName
<< " propertyName = " << propertyName << " value = " << value;

if (size != 0) {
cdebug << " (" << size << " elems)";
}

cdebug << std::endl;
// DebugBreak();
}

#endif // DEBUG
15 changes: 15 additions & 0 deletions vnext/Microsoft.ReactNative/TestHook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include <folly/dynamic.h>
#include <string>
#include <vector>

struct TestHook {
static void NotifyUnimplementedProperty(
const std::string &viewManager,
const std::string &reactClassName,
const std::string &propertyName,
const folly::dynamic &propertyValue);
static std::vector<std::string> layoutProperties;
};
5 changes: 5 additions & 0 deletions vnext/Microsoft.ReactNative/getLayoutProps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This script produces the values for the layoutProperties vector
# in TestHook.cpp
$page = Invoke-WebRequest "https://reactnative.dev/docs/layout-props"
$lines = $page.Content.Split('</a><code>') | select -skip 1
$lines -replace ('\n','') -replace ('</code>.*', '') | % { Write-Host "`"$_`", "}
4 changes: 3 additions & 1 deletion vnext/ReactUWP/ReactUWP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
$(ReactNativeWindowsDir)Shared;
$(ReactNativeWindowsDir)stubs;
$(YogaDir);
%(AdditionalIncludeDirectories)
%(AdditionalIncludeDirectories);
$(ReactNativeWindowsDir)Microsoft.ReactNative;
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(CHAKRACOREUWP)'=='true'">$(ChakraCoreInclude);$(ChakraCoreDebugInclude);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
Expand Down Expand Up @@ -280,6 +281,7 @@
<ClCompile Include="Modules\Animated\SpringAnimationDriver.cpp" />
<ClCompile Include="Modules\Animated\TrackingAnimatedNode.cpp" />
<ClCompile Include="Modules\AppearanceModule.cpp" />
<ClCompile Include="TestHookMock.cpp" />
<ClCompile Include="Threading\BatchingUIMessageQueueThread.cpp" />
<ClCompile Include="Threading\MessageQueueThreadFactory.cpp" />
<ClCompile Include="TurboModule\TurboModuleUtils.cpp" />
Expand Down
1 change: 1 addition & 0 deletions vnext/ReactUWP/ReactUWP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
<Filter>Views</Filter>
</ClCompile>
<ClCompile Include="Modules\AppearanceModule.cpp" />
<ClCompile Include="TestHookMock.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\ReactUWP\InstanceFactory.h">
Expand Down
7 changes: 7 additions & 0 deletions vnext/ReactUWP/TestHookMock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "TestHook.h"

void TestHook::NotifyUnimplementedProperty(
const std::string &,
const std::string &,
const std::string &,
const folly::dynamic &) {}
38 changes: 1 addition & 37 deletions vnext/ReactUWP/Views/ViewManagerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <IReactInstance.h>
#include <IXamlRootView.h>
#include <TestHook.h>
#include <Views/ShadowNodeBase.h>

using namespace folly;
Expand Down Expand Up @@ -275,43 +276,6 @@ void ViewManagerBase::NotifyUnimplementedProperty(
#endif // DEBUG
}

#ifdef DEBUG

void ViewManagerBase::TestHook::NotifyUnimplementedProperty(
const std::string &viewManager,
const std::string &reactClassName,
const std::string &propertyName,
const folly::dynamic &propertyValue) {
std::string value;
size_t size{};
try {
if (propertyValue.isObject()) {
value = "[Object]";
} else if (propertyValue.isNull()) {
value = "[Null]";
} else if (propertyValue.isArray()) {
size = propertyValue.size();
value = "[Array]";
} else {
value = propertyValue.asString();
}
} catch (const TypeError &e) {
value = e.what();
}

cdebug << "[UnimplementedProperty] ViewManager = " << viewManager << " elementClass = " << reactClassName
<< " propertyName = " << propertyName << " value = " << value;

if (size != 0) {
cdebug << " (" << size << " elems)";
}

cdebug << std::endl;
// DebugBreak();
}

#endif // DEBUG

void ViewManagerBase::SetLayoutProps(
ShadowNodeBase &nodeToUpdate,
const XamlView &viewToUpdate,
Expand Down
10 changes: 1 addition & 9 deletions vnext/include/ReactUWP/Views/ViewManagerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,7 @@ class REACTWINDOWS_EXPORT ViewManagerBase : public facebook::react::IViewManager
ShadowNodeBase *nodeToUpdate,
const std::string &propertyName,
const folly::dynamic &value);
#ifdef DEBUG
struct TestHook {
static void NotifyUnimplementedProperty(
const std::string &viewManager,
const std::string &reactClassName,
const std::string &propertyName,
const folly::dynamic &propertyValue);
};
#endif

protected:
std::weak_ptr<IReactInstance> m_wkReactInstance;
};
Expand Down