Skip to content

Commit

Permalink
Create option for out-of-tree platforms to customize View traits (fac…
Browse files Browse the repository at this point in the history
…ebook#38580)

Summary:
Pull Request resolved: facebook#38580

We already have a differential between Android and iOS View props that force view flattening (or unflattening) behaviors. Other out-of-tree platforms may have a need to customize view flattening behaviors.

This change adds a ViewTraitsInitializer header that out of tree platforms can inject to include platform-specific ViewProps fields when considering view flattening behaviors.

## Changelog:
[General] [Added] - Support customization of View traits for flattening in out of tree platform Fabric implementations

Reviewed By: christophpurrer

Differential Revision: D47721377

fbshipit-source-id: 9651860fc3fa2fcbaa508e28836c68f5f6636460
  • Loading branch information
rozele authored and facebook-github-bot committed Jul 25, 2023
1 parent 31d5c57 commit 8f8678e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ViewShadowNode.h"
#include <react/config/ReactNativeConfig.h>
#include <react/renderer/components/view/ViewTraitsInitializer.h>
#include <react/renderer/components/view/primitives.h>
#include <react/utils/CoreFeatures.h>

Expand Down Expand Up @@ -54,24 +55,13 @@ void ViewShadowNode::initialize() noexcept {
viewProps.accessibilityElementsHidden ||
viewProps.accessibilityViewIsModal ||
viewProps.importantForAccessibility != ImportantForAccessibility::Auto ||
viewProps.removeClippedSubviews;

#ifdef ANDROID
formsStackingContext = formsStackingContext || viewProps.elevation != 0;
#endif
viewProps.removeClippedSubviews ||
ViewTraitsInitializer::formsStackingContext(viewProps);

bool formsView = formsStackingContext ||
isColorMeaningful(viewProps.backgroundColor) ||
!(viewProps.yogaStyle.border() == YGStyle::Edges{}) ||
!viewProps.testId.empty();

#ifdef ANDROID
formsView = formsView || viewProps.nativeBackground.has_value() ||
viewProps.nativeForeground.has_value() || viewProps.focusable ||
viewProps.hasTVPreferredFocus ||
viewProps.needsOffscreenAlphaCompositing ||
viewProps.renderToHardwareTextureAndroid;
#endif
!viewProps.testId.empty() || ViewTraitsInitializer::formsView(viewProps);

if (formsView) {
traits_.set(ShadowNodeTraits::Trait::FormsView);
Expand All @@ -85,9 +75,7 @@ void ViewShadowNode::initialize() noexcept {
traits_.unset(ShadowNodeTraits::Trait::FormsStackingContext);
}

#ifdef ANDROID
traits_.set(ShadowNodeTraits::Trait::AndroidMapBufferPropsSupported);
#endif
traits_.set(ViewTraitsInitializer::extraTraits());
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/ShadowNodeTraits.h>

namespace facebook::react::ViewTraitsInitializer {

static bool formsStackingContext(ViewProps const &viewProps) {
return viewProps.elevation != 0;
}

static bool formsView(ViewProps const &viewProps) {
return viewProps.nativeBackground.has_value() ||
viewProps.nativeForeground.has_value() || viewProps.focusable ||
viewProps.hasTVPreferredFocus ||
viewProps.needsOffscreenAlphaCompositing ||
viewProps.renderToHardwareTextureAndroid;
}

static ShadowNodeTraits::Trait extraTraits() {
return ShadowNodeTraits::Trait::AndroidMapBufferPropsSupported;
}

} // namespace facebook::react::ViewTraitsInitializer
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/ShadowNodeTraits.h>

namespace facebook::react::ViewTraitsInitializer {

static bool formsStackingContext(ViewProps const &props) {
return false;
}

static bool formsView(ViewProps const &props) {
return false;
}

static ShadowNodeTraits::Trait extraTraits() {
return ShadowNodeTraits::Trait::None;
}

} // namespace facebook::react::ViewTraitsInitializer

0 comments on commit 8f8678e

Please sign in to comment.