Skip to content

Commit

Permalink
Convert ReactViewManager, ReactClippingViewManager to Kotlin (#46578)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46578

Pre-req for converting ReactViewGroup without affecting API visibility.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D62776270

fbshipit-source-id: 09a81c91a1c95685b36f4417cb1b1a2852dd7194
  • Loading branch information
Thomas Nardone authored and facebook-github-bot committed Sep 19, 2024
1 parent 5f49e27 commit d80e1e9
Show file tree
Hide file tree
Showing 5 changed files with 470 additions and 522 deletions.
9 changes: 7 additions & 2 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -8371,6 +8371,8 @@ public class com/facebook/react/views/view/ReactViewGroup : android/view/ViewGro
}

public class com/facebook/react/views/view/ReactViewManager : com/facebook/react/views/view/ReactClippingViewManager {
public static final field Companion Lcom/facebook/react/views/view/ReactViewManager$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/view/ReactViewGroup;
Expand All @@ -8381,7 +8383,7 @@ public class com/facebook/react/views/view/ReactViewManager : com/facebook/react
public fun nextFocusLeft (Lcom/facebook/react/views/view/ReactViewGroup;I)V
public fun nextFocusRight (Lcom/facebook/react/views/view/ReactViewGroup;I)V
public fun nextFocusUp (Lcom/facebook/react/views/view/ReactViewGroup;I)V
protected synthetic fun prepareToRecycleView (Lcom/facebook/react/uimanager/ThemedReactContext;Landroid/view/View;)Landroid/view/View;
public synthetic fun prepareToRecycleView (Lcom/facebook/react/uimanager/ThemedReactContext;Landroid/view/View;)Landroid/view/View;
protected fun prepareToRecycleView (Lcom/facebook/react/uimanager/ThemedReactContext;Lcom/facebook/react/views/view/ReactViewGroup;)Lcom/facebook/react/views/view/ReactViewGroup;
public synthetic fun receiveCommand (Landroid/view/View;ILcom/facebook/react/bridge/ReadableArray;)V
public synthetic fun receiveCommand (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
Expand Down Expand Up @@ -8410,7 +8412,7 @@ public class com/facebook/react/views/view/ReactViewManager : com/facebook/react
public fun setOverflow (Lcom/facebook/react/views/view/ReactViewGroup;Ljava/lang/String;)V
public fun setPointerEvents (Lcom/facebook/react/views/view/ReactViewGroup;Ljava/lang/String;)V
public fun setTVPreferredFocus (Lcom/facebook/react/views/view/ReactViewGroup;Z)V
protected synthetic fun setTransformProperty (Landroid/view/View;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;)V
public synthetic fun setTransformProperty (Landroid/view/View;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;)V
protected fun setTransformProperty (Lcom/facebook/react/views/view/ReactViewGroup;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/ReadableArray;)V
}

Expand All @@ -8421,6 +8423,9 @@ public class com/facebook/react/views/view/ReactViewManager$$PropsSetter : com/f
public fun setProperty (Lcom/facebook/react/views/view/ReactViewManager;Lcom/facebook/react/views/view/ReactViewGroup;Ljava/lang/String;Ljava/lang/Object;)V
}

public final class com/facebook/react/views/view/ReactViewManager$Companion {
}

public final class com/facebook/react/views/view/ViewGroupClickEvent : com/facebook/react/uimanager/events/Event {
public fun <init> (I)V
public fun <init> (II)V
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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.
*/

package com.facebook.react.views.view

import android.view.View
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.uimanager.ReactClippingViewGroupHelper
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.annotations.ReactProp

/**
* View manager which handles clipped subviews. Useful for custom views which extends from
* [com.facebook.react.views.view.ReactViewGroup]
*/
public abstract class ReactClippingViewManager<T : ReactViewGroup> : ViewGroupManager<T>() {

@ReactProp(name = ReactClippingViewGroupHelper.PROP_REMOVE_CLIPPED_SUBVIEWS)
public open fun setRemoveClippedSubviews(view: T, removeClippedSubviews: Boolean) {
UiThreadUtil.assertOnUiThread()
view.removeClippedSubviews = removeClippedSubviews
}

override fun addView(parent: T, child: View, index: Int) {
UiThreadUtil.assertOnUiThread()
if (parent.removeClippedSubviews) {
parent.addViewWithSubviewClippingEnabled(child, index)
} else {
parent.addView(child, index)
}
}

override fun getChildCount(parent: T): Int =
if (parent.removeClippedSubviews) {
parent.allChildrenCount
} else {
parent.childCount
}

override fun getChildAt(parent: T, index: Int): View? =
if (parent.removeClippedSubviews) {
parent.getChildAtWithSubviewClippingEnabled(index)
} else {
parent.getChildAt(index)
}

override fun removeViewAt(parent: T, index: Int) {
UiThreadUtil.assertOnUiThread()
if (parent.removeClippedSubviews) {
val child = getChildAt(parent, index) ?: return
if (child.parent != null) {
parent.removeView(child)
} else {
parent.removeViewWithSubviewClippingEnabled(child)
}
} else {
parent.removeViewAt(index)
}
}

override fun removeAllViews(parent: T) {
UiThreadUtil.assertOnUiThread()
if (parent.removeClippedSubviews) {
parent.removeAllViewsWithSubviewClippingEnabled()
} else {
parent.removeAllViews()
}
}
}
Loading

0 comments on commit d80e1e9

Please sign in to comment.