mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Convert ReactScrollView and ReactNestedScrollView to Kotlin
Summary: Convert `ReactScrollView.java` to `ReactScrollView.kt` and update the `generate-nested-scroll-view.js` script to generate `ReactNestedScrollView.kt` from the Kotlin source. Key changes: - `ReactScrollView.java` replaced by idiomatic `ReactScrollView.kt` - `ReactNestedScrollView.java` replaced by generated `ReactNestedScrollView.kt` - Generation script updated for Kotlin source/output file paths and transformations - BUCK file updated to reference `.kt` files in the verification genrule - `ReactScrollViewManager.kt` updated to use Kotlin property access syntax for `scrollEnabled`, `stateWrapper`, and `fadingEdgeLengthStart/End` - Public API surface preserved: only additive `synthetic` constructor from `JvmOverloads` Changelog: [Android][Changed] - Convert `ReactScrollView` and `ReactNestedScrollView` from Java to Kotlin Reviewed By: Abbondanzo Differential Revision: D107236882 fbshipit-source-id: 8537dc2521774cb8262950f0cb70cf1e227a372e
This commit is contained in:
1 parent
75eaff4c03
commit
9d65e6c497
10 files changed
+2716
-3349
No files matched your search
@@ -5429,6 +5429,30 @@ public abstract interface class com/facebook/react/views/scroll/FpsListener {
|
||||
public abstract fun isEnabled ()Z
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper : com/facebook/react/bridge/UIManagerListener {
|
||||
public fun <init> (Landroid/view/ViewGroup;Z)V
|
||||
public fun didDispatchMountItems (Lcom/facebook/react/bridge/UIManager;)V
|
||||
public fun didMountItems (Lcom/facebook/react/bridge/UIManager;)V
|
||||
public fun didScheduleMountItems (Lcom/facebook/react/bridge/UIManager;)V
|
||||
public final fun getConfig ()Lcom/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper$Config;
|
||||
public final fun setConfig (Lcom/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper$Config;)V
|
||||
public final fun start ()V
|
||||
public final fun stop ()V
|
||||
public fun willDispatchViewUpdates (Lcom/facebook/react/bridge/UIManager;)V
|
||||
public fun willMountItems (Lcom/facebook/react/bridge/UIManager;)V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper$Config {
|
||||
public static final field Companion Lcom/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper$Config$Companion;
|
||||
public static final fun fromReadableMap (Lcom/facebook/react/bridge/ReadableMap;)Lcom/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper$Config;
|
||||
public final fun getAutoScrollToTopThreshold ()Ljava/lang/Integer;
|
||||
public final fun getMinIndexForVisible ()I
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper$Config$Companion {
|
||||
public final fun fromReadableMap (Lcom/facebook/react/bridge/ReadableMap;)Lcom/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper$Config;
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/scroll/OnScrollDispatchHelper {
|
||||
public fun <init> ()V
|
||||
public final fun getXFlingVelocity ()F
|
||||
@@ -5598,6 +5622,7 @@ public final class com/facebook/react/views/scroll/ReactHorizontalScrollViewMana
|
||||
public class com/facebook/react/views/scroll/ReactScrollView : android/widget/ScrollView, android/view/View$OnLayoutChangeListener, android/view/ViewGroup$OnHierarchyChangeListener, com/facebook/react/uimanager/ReactClippingViewGroup, com/facebook/react/uimanager/ReactOverflowViewWithInset, com/facebook/react/views/scroll/ReactAccessibleScrollView, com/facebook/react/views/scroll/ReactScrollViewHelper$HasFlingAnimator, com/facebook/react/views/scroll/ReactScrollViewHelper$HasScrollEventThrottle, com/facebook/react/views/scroll/ReactScrollViewHelper$HasScrollState, com/facebook/react/views/scroll/ReactScrollViewHelper$HasSmoothScroll, com/facebook/react/views/scroll/ReactScrollViewHelper$HasStateWrapper, com/facebook/react/views/scroll/VirtualViewContainer {
|
||||
public fun <init> (Landroid/content/Context;)V
|
||||
public fun <init> (Landroid/content/Context;Lcom/facebook/react/views/scroll/FpsListener;)V
|
||||
public synthetic fun <init> (Landroid/content/Context;Lcom/facebook/react/views/scroll/FpsListener;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun abortAnimation ()V
|
||||
public fun dispatchGenericMotionEvent (Landroid/view/MotionEvent;)Z
|
||||
public fun draw (Landroid/graphics/Canvas;)V
|
||||
@@ -5925,6 +5950,28 @@ public abstract interface class com/facebook/react/views/scroll/VirtualView {
|
||||
public abstract fun onModeChange (Lcom/facebook/react/views/virtual/VirtualViewMode;Landroid/graphics/Rect;)V
|
||||
}
|
||||
|
||||
public abstract class com/facebook/react/views/scroll/VirtualViewContainerState {
|
||||
public static final field Companion Lcom/facebook/react/views/scroll/VirtualViewContainerState$Companion;
|
||||
public fun <init> (Landroid/view/ViewGroup;)V
|
||||
public static final fun create (Landroid/view/ViewGroup;)Lcom/facebook/react/views/scroll/VirtualViewContainerState;
|
||||
protected final fun getEmptyRect ()Landroid/graphics/Rect;
|
||||
protected final fun getPrerenderRatio ()D
|
||||
protected final fun getPrerenderRect ()Landroid/graphics/Rect;
|
||||
protected final fun getScrollView ()Landroid/view/ViewGroup;
|
||||
protected abstract fun getVirtualViews ()Ljava/util/Collection;
|
||||
protected final fun getVisibleRect ()Landroid/graphics/Rect;
|
||||
public fun onChange (Lcom/facebook/react/views/scroll/VirtualView;)V
|
||||
public fun remove (Lcom/facebook/react/views/scroll/VirtualView;)V
|
||||
protected abstract fun updateModes (Lcom/facebook/react/views/scroll/VirtualView;)V
|
||||
public static synthetic fun updateModes$default (Lcom/facebook/react/views/scroll/VirtualViewContainerState;Lcom/facebook/react/views/scroll/VirtualView;ILjava/lang/Object;)V
|
||||
protected final fun updateRects ()V
|
||||
public final fun updateState ()V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/scroll/VirtualViewContainerState$Companion {
|
||||
public final fun create (Landroid/view/ViewGroup;)Lcom/facebook/react/views/scroll/VirtualViewContainerState;
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/swiperefresh/ReactSwipeRefreshLayout : androidx/swiperefreshlayout/widget/SwipeRefreshLayout {
|
||||
public fun <init> (Lcom/facebook/react/bridge/ReactContext;)V
|
||||
public fun canChildScrollUp ()Z
|
||||
|
||||
+11
-8
@@ -28,12 +28,12 @@ import java.lang.ref.WeakReference
|
||||
* This uses UIManager to listen to updates and capture position of items before and after layout.
|
||||
*/
|
||||
@OptIn(UnstableReactNativeAPI::class)
|
||||
internal class MaintainVisibleScrollPositionHelper<ScrollViewT>(
|
||||
public class MaintainVisibleScrollPositionHelper<ScrollViewT>(
|
||||
private val scrollView: ScrollViewT,
|
||||
private val horizontal: Boolean,
|
||||
) : UIManagerListener where ScrollViewT : HasSmoothScroll?, ScrollViewT : ViewGroup? {
|
||||
|
||||
var config: Config? = null
|
||||
public var config: Config? = null
|
||||
private var firstVisibleViewRef: WeakReference<View>? = null
|
||||
private var prevFirstVisibleFrame: Rect? = null
|
||||
private var isListening = false
|
||||
@@ -50,11 +50,14 @@ internal class MaintainVisibleScrollPositionHelper<ScrollViewT>(
|
||||
)
|
||||
)
|
||||
|
||||
class Config
|
||||
internal constructor(val minIndexForVisible: Int, val autoScrollToTopThreshold: Int?) {
|
||||
companion object {
|
||||
public class Config
|
||||
internal constructor(
|
||||
public val minIndexForVisible: Int,
|
||||
public val autoScrollToTopThreshold: Int?,
|
||||
) {
|
||||
public companion object {
|
||||
@JvmStatic
|
||||
fun fromReadableMap(value: ReadableMap): Config {
|
||||
public fun fromReadableMap(value: ReadableMap): Config {
|
||||
val minIndexForVisible = value.getInt("minIndexForVisible")
|
||||
val autoScrollToTopThreshold =
|
||||
if (value.hasKey("autoscrollToTopThreshold")) value.getInt("autoscrollToTopThreshold")
|
||||
@@ -65,7 +68,7 @@ internal class MaintainVisibleScrollPositionHelper<ScrollViewT>(
|
||||
}
|
||||
|
||||
/** Start listening to view hierarchy updates. Should be called when this is created. */
|
||||
fun start() {
|
||||
public fun start() {
|
||||
if (isListening) {
|
||||
return
|
||||
}
|
||||
@@ -74,7 +77,7 @@ internal class MaintainVisibleScrollPositionHelper<ScrollViewT>(
|
||||
}
|
||||
|
||||
/** Stop listening to view hierarchy updates. Should be called before this is destroyed. */
|
||||
fun stop() {
|
||||
public fun stop() {
|
||||
if (!isListening) {
|
||||
return
|
||||
}
|
||||
|
||||
-1654
File diff suppressed because it is too large.
Load diff
+1311
File diff suppressed because it is too large.
Load diff
+7
-7
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<585a90a2f11c5bba8b3e2d011912d302>>
|
||||
* @generated SignedSource<<d321b1f5f7a34b5717cb7ef5300dda96>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ constructor(private val fpsListener: FpsListener? = null) :
|
||||
|
||||
@ReactProp(name = "scrollEnabled", defaultBoolean = true)
|
||||
public fun setScrollEnabled(view: ReactNestedScrollView, value: Boolean) {
|
||||
view.setScrollEnabled(value)
|
||||
view.scrollEnabled = value
|
||||
|
||||
// Set focusable to match whether scroll is enabled. This improves keyboarding
|
||||
// experience by not making scrollview a tab stop when you cannot interact with it.
|
||||
@@ -343,8 +343,8 @@ constructor(private val fpsListener: FpsListener? = null) :
|
||||
public fun setFadingEdgeLength(view: ReactNestedScrollView, value: Dynamic) {
|
||||
when (value.type) {
|
||||
ReadableType.Number -> {
|
||||
view.setFadingEdgeLengthStart(value.asInt())
|
||||
view.setFadingEdgeLengthEnd(value.asInt())
|
||||
view.fadingEdgeLengthStart = value.asInt()
|
||||
view.fadingEdgeLengthEnd = value.asInt()
|
||||
}
|
||||
ReadableType.Map -> {
|
||||
value.asMap()?.let { map ->
|
||||
@@ -356,8 +356,8 @@ constructor(private val fpsListener: FpsListener? = null) :
|
||||
if (map.hasKey("end") && map.getInt("end") > 0) {
|
||||
end = map.getInt("end")
|
||||
}
|
||||
view.setFadingEdgeLengthStart(start)
|
||||
view.setFadingEdgeLengthEnd(end)
|
||||
view.fadingEdgeLengthStart = start
|
||||
view.fadingEdgeLengthEnd = end
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@@ -396,7 +396,7 @@ constructor(private val fpsListener: FpsListener? = null) :
|
||||
props: ReactStylesDiffMap,
|
||||
stateWrapper: StateWrapper,
|
||||
): Any? {
|
||||
view.setStateWrapper(stateWrapper)
|
||||
view.stateWrapper = stateWrapper
|
||||
if (
|
||||
ReactNativeFeatureFlags.enableViewCulling() ||
|
||||
ReactNativeFeatureFlags.useTraitHiddenOnAndroid()
|
||||
|
||||
-1646
File diff suppressed because it is too large.
Load diff
+1303
File diff suppressed because it is too large.
Load diff
+6
-6
@@ -82,7 +82,7 @@ constructor(private val fpsListener: FpsListener? = null) :
|
||||
|
||||
@ReactProp(name = "scrollEnabled", defaultBoolean = true)
|
||||
public fun setScrollEnabled(view: ReactScrollView, value: Boolean) {
|
||||
view.setScrollEnabled(value)
|
||||
view.scrollEnabled = value
|
||||
|
||||
// Set focusable to match whether scroll is enabled. This improves keyboarding
|
||||
// experience by not making scrollview a tab stop when you cannot interact with it.
|
||||
@@ -335,8 +335,8 @@ constructor(private val fpsListener: FpsListener? = null) :
|
||||
public fun setFadingEdgeLength(view: ReactScrollView, value: Dynamic) {
|
||||
when (value.type) {
|
||||
ReadableType.Number -> {
|
||||
view.setFadingEdgeLengthStart(value.asInt())
|
||||
view.setFadingEdgeLengthEnd(value.asInt())
|
||||
view.fadingEdgeLengthStart = value.asInt()
|
||||
view.fadingEdgeLengthEnd = value.asInt()
|
||||
}
|
||||
ReadableType.Map -> {
|
||||
value.asMap()?.let { map ->
|
||||
@@ -348,8 +348,8 @@ constructor(private val fpsListener: FpsListener? = null) :
|
||||
if (map.hasKey("end") && map.getInt("end") > 0) {
|
||||
end = map.getInt("end")
|
||||
}
|
||||
view.setFadingEdgeLengthStart(start)
|
||||
view.setFadingEdgeLengthEnd(end)
|
||||
view.fadingEdgeLengthStart = start
|
||||
view.fadingEdgeLengthEnd = end
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@@ -388,7 +388,7 @@ constructor(private val fpsListener: FpsListener? = null) :
|
||||
props: ReactStylesDiffMap,
|
||||
stateWrapper: StateWrapper,
|
||||
): Any? {
|
||||
view.setStateWrapper(stateWrapper)
|
||||
view.stateWrapper = stateWrapper
|
||||
if (
|
||||
ReactNativeFeatureFlags.enableViewCulling() ||
|
||||
ReactNativeFeatureFlags.useTraitHiddenOnAndroid()
|
||||
|
||||
+18
-8
@@ -14,7 +14,7 @@ import com.facebook.react.views.virtual.VirtualViewMode
|
||||
import java.util.*
|
||||
|
||||
internal interface VirtualViewContainer {
|
||||
public val virtualViewContainerState: VirtualViewContainerState
|
||||
val virtualViewContainerState: VirtualViewContainerState
|
||||
}
|
||||
|
||||
public interface VirtualView {
|
||||
@@ -43,7 +43,17 @@ internal fun rectsOverlap(rect1: Rect, rect2: Rect): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
internal abstract class VirtualViewContainerState {
|
||||
/**
|
||||
* Manages the state and visibility tracking of virtual views within a scroll container.
|
||||
*
|
||||
* Virtual views are lightweight representations of off-screen content that can transition between
|
||||
* rendering modes (e.g., visible, prerendered, hidden) based on their position relative to the
|
||||
* scroll viewport. Subclasses implement the specific strategy for tracking and updating these
|
||||
* views.
|
||||
*
|
||||
* Use [create] to obtain an instance appropriate for the current feature flag configuration.
|
||||
*/
|
||||
public abstract class VirtualViewContainerState {
|
||||
protected val prerenderRatio: Double = ReactNativeFeatureFlags.virtualViewPrerenderRatio()
|
||||
protected abstract val virtualViews: MutableCollection<VirtualView>
|
||||
protected val emptyRect: Rect = Rect()
|
||||
@@ -51,9 +61,9 @@ internal abstract class VirtualViewContainerState {
|
||||
protected val prerenderRect: Rect = Rect()
|
||||
protected val scrollView: ViewGroup
|
||||
|
||||
companion object {
|
||||
public companion object {
|
||||
@JvmStatic
|
||||
fun create(scrollView: ViewGroup): VirtualViewContainerState {
|
||||
public fun create(scrollView: ViewGroup): VirtualViewContainerState {
|
||||
return if (ReactNativeFeatureFlags.enableVirtualViewContainerStateExperimental()) {
|
||||
VirtualViewContainerStateExperimental(scrollView)
|
||||
} else {
|
||||
@@ -62,23 +72,23 @@ internal abstract class VirtualViewContainerState {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(scrollView: ViewGroup) {
|
||||
public constructor(scrollView: ViewGroup) {
|
||||
this.scrollView = scrollView
|
||||
}
|
||||
|
||||
open fun onChange(virtualView: VirtualView) {
|
||||
public open fun onChange(virtualView: VirtualView) {
|
||||
virtualViews.add(virtualView)
|
||||
updateModes(virtualView)
|
||||
}
|
||||
|
||||
open fun remove(virtualView: VirtualView) {
|
||||
public open fun remove(virtualView: VirtualView) {
|
||||
assert(virtualViews.remove(virtualView)) {
|
||||
"Attempting to remove non-existent VirtualView: ${virtualView.virtualViewID}"
|
||||
}
|
||||
}
|
||||
|
||||
// Called on ScrollView onLayout or onScroll
|
||||
fun updateState() {
|
||||
public fun updateState() {
|
||||
updateModes()
|
||||
}
|
||||
|
||||
|
||||
+13
-20
@@ -11,8 +11,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generates ReactNestedScrollView.java and ReactNestedScrollViewManager.kt from
|
||||
* ReactScrollView.java and ReactScrollViewManager.kt respectively.
|
||||
* Generates ReactNestedScrollView.kt and ReactNestedScrollViewManager.kt from
|
||||
* ReactScrollView.kt and ReactScrollViewManager.kt respectively.
|
||||
*
|
||||
* This script creates variants that use NestedScrollView instead of ScrollView
|
||||
* for experimentation purposes.
|
||||
@@ -101,17 +101,17 @@ function replaceCopyrightHeader(content, sourceFile) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform ReactScrollView.java to ReactNestedScrollView.java
|
||||
* Transform ReactScrollView.kt to ReactNestedScrollView.kt
|
||||
*/
|
||||
function transformScrollView(content) {
|
||||
// Replace import
|
||||
// Replace import (Kotlin imports have no semicolons)
|
||||
content = content.replace(
|
||||
'import android.widget.ScrollView;',
|
||||
'import androidx.core.widget.NestedScrollView;',
|
||||
'import android.widget.ScrollView',
|
||||
'import androidx.core.widget.NestedScrollView',
|
||||
);
|
||||
|
||||
// Replace standalone ScrollView with NestedScrollView (not when part of another word)
|
||||
// This handles: "extends ScrollView", "ScrollView.class", etc.
|
||||
// This handles: ": ScrollView(context)", "ScrollView::class.java", etc.
|
||||
// But NOT: ReactScrollView, NestedScrollView, ScrollViewHelper, etc.
|
||||
content = content.replace(
|
||||
/(?<![A-Za-z])ScrollView(?!Helper|Manager|CommandHelper|Interface|Accessible|Accessibility)/g,
|
||||
@@ -121,21 +121,14 @@ function transformScrollView(content) {
|
||||
// Replace ReactScrollView with ReactNestedScrollView
|
||||
content = replaceClassNames(content);
|
||||
|
||||
// Fix visibility differences between ScrollView and NestedScrollView:
|
||||
// NestedScrollView.onAttachedToWindow() is public, not protected
|
||||
// Make the class internal to keep it out of the public API
|
||||
content = content.replace(
|
||||
'protected void onAttachedToWindow()',
|
||||
'public void onAttachedToWindow()',
|
||||
);
|
||||
|
||||
// Make the class package-private (remove public) to keep it internal
|
||||
content = content.replace(
|
||||
'public class ReactNestedScrollView',
|
||||
'class ReactNestedScrollView',
|
||||
'public open class ReactNestedScrollView',
|
||||
'internal open class ReactNestedScrollView',
|
||||
);
|
||||
|
||||
// Remove original copyright header and add generated header
|
||||
content = replaceCopyrightHeader(content, 'ReactScrollView.java');
|
||||
content = replaceCopyrightHeader(content, 'ReactScrollView.kt');
|
||||
|
||||
return content;
|
||||
}
|
||||
@@ -246,8 +239,8 @@ function main() {
|
||||
|
||||
const filesToGenerate = [
|
||||
{
|
||||
source: path.join(sourceDir, 'ReactScrollView.java'),
|
||||
output: path.join(sourceDir, 'ReactNestedScrollView.java'),
|
||||
source: path.join(sourceDir, 'ReactScrollView.kt'),
|
||||
output: path.join(sourceDir, 'ReactNestedScrollView.kt'),
|
||||
transform: transformScrollView,
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user