Skip to content

Commit

Permalink
Fix interactions between removeClippedSubviews and RTL by applying Ho…
Browse files Browse the repository at this point in the history
…rizontalScrollContentView translation during layout metric assignment (#46685)

Summary:
Pull Request resolved: #46685

This attempts a similar fix to D59566611, but keeps the removedClippedSubviews logic as is, instead moving the current translation done in ReactHorizontalScrollContainerView onLayout to ShadowNode layout metric assignment (so the world is consistent from very early on, and `removeClippedSubviews` never sees coordinates before translation),

I suspect doing this at the ShadowNode layer might also result in some fixes to DevTools in RTL.

This should let us roll out setAndroidLayoutDirection again.

Changelog:
[Android][Fixed] - Fix interactions between removeClippedSubviews and RTL

Reviewed By: mdvacca

Differential Revision: D63318754

fbshipit-source-id: 828e103e2ad21c7e886e39c163474b10ebd5099e
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 28, 2024
1 parent a396f6c commit 513e966
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 88 deletions.
13 changes: 2 additions & 11 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -7029,27 +7029,18 @@ public final class com/facebook/react/views/scroll/OnScrollDispatchHelper {
public final fun onScrollChanged (II)Z
}

public class com/facebook/react/views/scroll/ReactHorizontalScrollContainerView : com/facebook/react/views/view/ReactViewGroup {
public fun <init> (Landroid/content/Context;)V
public fun getLayoutDirection ()I
protected fun onLayout (ZIIII)V
public fun setRemoveClippedSubviews (Z)V
}

public final class com/facebook/react/views/scroll/ReactHorizontalScrollContainerViewManager : com/facebook/react/views/view/ReactClippingViewManager {
public final class com/facebook/react/views/scroll/ReactHorizontalScrollContainerViewManager : com/facebook/react/views/view/ReactViewManager {
public static final field Companion Lcom/facebook/react/views/scroll/ReactHorizontalScrollContainerViewManager$Companion;
public static final field REACT_CLASS Ljava/lang/String;
public fun <init> ()V
public synthetic fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Landroid/view/View;
public fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Lcom/facebook/react/views/scroll/ReactHorizontalScrollContainerView;
public fun getName ()Ljava/lang/String;
}

public class com/facebook/react/views/scroll/ReactHorizontalScrollContainerViewManager$$PropsSetter : com/facebook/react/uimanager/ViewManagerPropertyUpdater$ViewManagerSetter {
public fun <init> ()V
public fun getProperties (Ljava/util/Map;)V
public synthetic fun setProperty (Lcom/facebook/react/uimanager/ViewManager;Landroid/view/View;Ljava/lang/String;Ljava/lang/Object;)V
public fun setProperty (Lcom/facebook/react/views/scroll/ReactHorizontalScrollContainerViewManager;Lcom/facebook/react/views/scroll/ReactHorizontalScrollContainerView;Ljava/lang/String;Ljava/lang/Object;)V
public fun setProperty (Lcom/facebook/react/views/scroll/ReactHorizontalScrollContainerViewManager;Lcom/facebook/react/views/view/ReactViewGroup;Ljava/lang/String;Ljava/lang/Object;)V
}

public final class com/facebook/react/views/scroll/ReactHorizontalScrollContainerViewManager$Companion {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@
package com.facebook.react.views.scroll

import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.views.view.ReactClippingViewManager
import com.facebook.react.views.view.ReactViewManager

/** View manager for {@link ReactHorizontalScrollContainerView} components. */
@ReactModule(name = ReactHorizontalScrollContainerViewManager.REACT_CLASS)
public class ReactHorizontalScrollContainerViewManager :
ReactClippingViewManager<ReactHorizontalScrollContainerView>() {

public class ReactHorizontalScrollContainerViewManager : ReactViewManager() {
override public fun getName(): String = REACT_CLASS

override public fun createViewInstance(
context: ThemedReactContext
): ReactHorizontalScrollContainerView = ReactHorizontalScrollContainerView(context)

public companion object {
public const val REACT_CLASS: String = "AndroidHorizontalScrollContentView"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <react/renderer/components/progressbar/AndroidProgressBarComponentDescriptor.h>
#include <react/renderer/components/rncore/ComponentDescriptors.h>
#include <react/renderer/components/safeareaview/SafeAreaViewComponentDescriptor.h>
#include <react/renderer/components/scrollview/AndroidHorizontalScrollContentViewComponentDescriptor.h>
#include <react/renderer/components/scrollview/ScrollViewComponentDescriptor.h>
#include <react/renderer/components/text/ParagraphComponentDescriptor.h>
#include <react/renderer/components/text/RawTextComponentDescriptor.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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/scrollview/AndroidHorizontalScrollContentViewShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h>

namespace facebook::react {

using AndroidHorizontalScrollContentViewComponentDescriptor =
ConcreteComponentDescriptor<AndroidHorizontalScrollContentViewShadowNode>;

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.
*/

#include <react/renderer/components/scrollview/AndroidHorizontalScrollContentViewShadowNode.h>

namespace facebook::react {

const char AndroidHorizontalScrollContentViewShadowNodeComponentName[] =
"AndroidHorizontalScrollContentView";

void AndroidHorizontalScrollContentViewShadowNode::layout(
LayoutContext layoutContext) {
ConcreteViewShadowNode::layout(layoutContext);

// When the layout direction is RTL, we expect Yoga to give us a layout
// that extends off the screen to the left so we re-center it with left=0
if (layoutMetrics_.layoutDirection == LayoutDirection::RightToLeft) {
layoutMetrics_.frame.origin.x = 0;
}
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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/ConcreteViewShadowNode.h>
#include <react/renderer/core/LayoutContext.h>

namespace facebook::react {

extern const char AndroidHorizontalScrollContentViewShadowNodeComponentName[];

class AndroidHorizontalScrollContentViewShadowNode final
: public ConcreteViewShadowNode<
AndroidHorizontalScrollContentViewShadowNodeComponentName,
ViewProps> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;
void layout(LayoutContext layoutContext) override;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ type NativeType = HostComponent<NativeProps>;

export default (codegenNativeComponent<NativeProps>(
'AndroidHorizontalScrollContentView',
{interfaceOnly: true},
): NativeType);

0 comments on commit 513e966

Please sign in to comment.