-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert ReactViewManager, ReactClippingViewManager to Kotlin (#46578)
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
1 parent
5f49e27
commit d80e1e9
Showing
5 changed files
with
470 additions
and
522 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 0 additions & 95 deletions
95
...ve/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactClippingViewManager.java
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
...tive/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactClippingViewManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
Oops, something went wrong.