mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migrate com.facebook.react.views.text.ReactScrollViewCommandHelper to Kotlin (#47619)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47619 As per title. Changelog: [Internal] Reviewed By: tdn120 Differential Revision: D65660776 fbshipit-source-id: ca238729f511a6e446dedd89515c88b26563aef8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9c11d7ca68
commit
6db883a56c
@@ -6921,14 +6921,21 @@ public class com/facebook/react/views/scroll/ReactScrollView : android/widget/Sc
|
||||
public fun updateClippingRect ()V
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/scroll/ReactScrollViewCommandHelper {
|
||||
public final class com/facebook/react/views/scroll/ReactScrollViewCommandHelper {
|
||||
public static final field COMMAND_FLASH_SCROLL_INDICATORS I
|
||||
public static final field COMMAND_SCROLL_TO I
|
||||
public static final field COMMAND_SCROLL_TO_END I
|
||||
public static final field Companion Lcom/facebook/react/views/scroll/ReactScrollViewCommandHelper$Companion;
|
||||
public fun <init> ()V
|
||||
public static fun getCommandsMap ()Ljava/util/Map;
|
||||
public static fun receiveCommand (Lcom/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollCommandHandler;Ljava/lang/Object;ILcom/facebook/react/bridge/ReadableArray;)V
|
||||
public static fun receiveCommand (Lcom/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollCommandHandler;Ljava/lang/Object;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
|
||||
public static final fun getCommandsMap ()Ljava/util/Map;
|
||||
public static final fun receiveCommand (Lcom/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollCommandHandler;Ljava/lang/Object;ILcom/facebook/react/bridge/ReadableArray;)V
|
||||
public static final fun receiveCommand (Lcom/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollCommandHandler;Ljava/lang/Object;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/scroll/ReactScrollViewCommandHelper$Companion {
|
||||
public final fun getCommandsMap ()Ljava/util/Map;
|
||||
public final fun receiveCommand (Lcom/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollCommandHandler;Ljava/lang/Object;ILcom/facebook/react/bridge/ReadableArray;)V
|
||||
public final fun receiveCommand (Lcom/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollCommandHandler;Ljava/lang/Object;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
|
||||
}
|
||||
|
||||
public abstract interface class com/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollCommandHandler {
|
||||
@@ -6937,14 +6944,16 @@ public abstract interface class com/facebook/react/views/scroll/ReactScrollViewC
|
||||
public abstract fun scrollToEnd (Ljava/lang/Object;Lcom/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollToEndCommandData;)V
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollToCommandData {
|
||||
public final class com/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollToCommandData {
|
||||
public final field mAnimated Z
|
||||
public final field mDestX I
|
||||
public final field mDestY I
|
||||
public fun <init> (IIZ)V
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollToEndCommandData {
|
||||
public final class com/facebook/react/views/scroll/ReactScrollViewCommandHelper$ScrollToEndCommandData {
|
||||
public final field mAnimated Z
|
||||
public fun <init> (Z)V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/scroll/ReactScrollViewHelper {
|
||||
|
||||
-141
@@ -1,141 +0,0 @@
|
||||
/*
|
||||
* 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.scroll;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Helper for view managers to handle commands like 'scrollTo'. Shared by {@link
|
||||
* ReactScrollViewManager} and {@link ReactHorizontalScrollViewManager}.
|
||||
*/
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public class ReactScrollViewCommandHelper {
|
||||
|
||||
public static final int COMMAND_SCROLL_TO = 1;
|
||||
public static final int COMMAND_SCROLL_TO_END = 2;
|
||||
public static final int COMMAND_FLASH_SCROLL_INDICATORS = 3;
|
||||
|
||||
public interface ScrollCommandHandler<T> {
|
||||
void scrollTo(T scrollView, ScrollToCommandData data);
|
||||
|
||||
void scrollToEnd(T scrollView, ScrollToEndCommandData data);
|
||||
|
||||
void flashScrollIndicators(T scrollView);
|
||||
}
|
||||
|
||||
public static class ScrollToCommandData {
|
||||
|
||||
public final int mDestX, mDestY;
|
||||
public final boolean mAnimated;
|
||||
|
||||
ScrollToCommandData(int destX, int destY, boolean animated) {
|
||||
mDestX = destX;
|
||||
mDestY = destY;
|
||||
mAnimated = animated;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ScrollToEndCommandData {
|
||||
|
||||
public final boolean mAnimated;
|
||||
|
||||
ScrollToEndCommandData(boolean animated) {
|
||||
mAnimated = animated;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Integer> getCommandsMap() {
|
||||
return MapBuilder.of(
|
||||
"scrollTo",
|
||||
COMMAND_SCROLL_TO,
|
||||
"scrollToEnd",
|
||||
COMMAND_SCROLL_TO_END,
|
||||
"flashScrollIndicators",
|
||||
COMMAND_FLASH_SCROLL_INDICATORS);
|
||||
}
|
||||
|
||||
public static <T> void receiveCommand(
|
||||
ScrollCommandHandler<T> viewManager,
|
||||
T scrollView,
|
||||
int commandType,
|
||||
@Nullable ReadableArray args) {
|
||||
Assertions.assertNotNull(viewManager);
|
||||
Assertions.assertNotNull(scrollView);
|
||||
switch (commandType) {
|
||||
case COMMAND_SCROLL_TO:
|
||||
{
|
||||
scrollTo(viewManager, scrollView, Assertions.assertNotNull(args));
|
||||
return;
|
||||
}
|
||||
case COMMAND_SCROLL_TO_END:
|
||||
{
|
||||
scrollToEnd(viewManager, scrollView, Assertions.assertNotNull(args));
|
||||
return;
|
||||
}
|
||||
case COMMAND_FLASH_SCROLL_INDICATORS:
|
||||
viewManager.flashScrollIndicators(scrollView);
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Unsupported command %d received by %s.",
|
||||
commandType, viewManager.getClass().getSimpleName()));
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void receiveCommand(
|
||||
ScrollCommandHandler<T> viewManager,
|
||||
T scrollView,
|
||||
String commandType,
|
||||
@Nullable ReadableArray args) {
|
||||
Assertions.assertNotNull(viewManager);
|
||||
Assertions.assertNotNull(scrollView);
|
||||
switch (commandType) {
|
||||
case "scrollTo":
|
||||
{
|
||||
scrollTo(viewManager, scrollView, Assertions.assertNotNull(args));
|
||||
return;
|
||||
}
|
||||
case "scrollToEnd":
|
||||
{
|
||||
scrollToEnd(viewManager, scrollView, Assertions.assertNotNull(args));
|
||||
return;
|
||||
}
|
||||
case "flashScrollIndicators":
|
||||
viewManager.flashScrollIndicators(scrollView);
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Unsupported command %s received by %s.",
|
||||
commandType, viewManager.getClass().getSimpleName()));
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void scrollTo(
|
||||
ScrollCommandHandler<T> viewManager, T scrollView, ReadableArray args) {
|
||||
int destX = Math.round(PixelUtil.toPixelFromDIP(args.getDouble(0)));
|
||||
int destY = Math.round(PixelUtil.toPixelFromDIP(args.getDouble(1)));
|
||||
boolean animated = args.getBoolean(2);
|
||||
viewManager.scrollTo(scrollView, new ScrollToCommandData(destX, destY, animated));
|
||||
}
|
||||
|
||||
private static <T> void scrollToEnd(
|
||||
ScrollCommandHandler<T> viewManager, T scrollView, ReadableArray args) {
|
||||
boolean animated = args.getBoolean(0);
|
||||
viewManager.scrollToEnd(scrollView, new ScrollToEndCommandData(animated));
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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.scroll
|
||||
|
||||
import com.facebook.react.bridge.ReadableArray
|
||||
import com.facebook.react.uimanager.PixelUtil
|
||||
|
||||
public class ReactScrollViewCommandHelper {
|
||||
|
||||
public companion object {
|
||||
public const val COMMAND_SCROLL_TO: Int = 1
|
||||
public const val COMMAND_SCROLL_TO_END: Int = 2
|
||||
public const val COMMAND_FLASH_SCROLL_INDICATORS: Int = 3
|
||||
|
||||
@JvmStatic
|
||||
public fun getCommandsMap(): Map<String, Int> =
|
||||
hashMapOf(
|
||||
"scrollTo" to COMMAND_SCROLL_TO,
|
||||
"scrollToEnd" to COMMAND_SCROLL_TO_END,
|
||||
"flashScrollIndicators" to COMMAND_FLASH_SCROLL_INDICATORS)
|
||||
|
||||
@JvmStatic
|
||||
public fun <T> receiveCommand(
|
||||
viewManager: ScrollCommandHandler<T>,
|
||||
scrollView: T,
|
||||
commandType: Int,
|
||||
args: ReadableArray?
|
||||
) {
|
||||
checkNotNull(viewManager)
|
||||
checkNotNull(scrollView)
|
||||
when (commandType) {
|
||||
COMMAND_SCROLL_TO -> scrollTo(viewManager, scrollView, checkNotNull(args))
|
||||
COMMAND_SCROLL_TO_END -> scrollToEnd(viewManager, scrollView, checkNotNull(args))
|
||||
COMMAND_FLASH_SCROLL_INDICATORS -> viewManager.flashScrollIndicators(scrollView)
|
||||
else ->
|
||||
throw IllegalArgumentException(
|
||||
"Unsupported command $commandType received by ${viewManager::class.java.simpleName}.")
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun <T> receiveCommand(
|
||||
viewManager: ScrollCommandHandler<T>,
|
||||
scrollView: T,
|
||||
commandType: String,
|
||||
args: ReadableArray?
|
||||
) {
|
||||
checkNotNull(viewManager)
|
||||
checkNotNull(scrollView)
|
||||
when (commandType) {
|
||||
"scrollTo" -> scrollTo(viewManager, scrollView, checkNotNull(args))
|
||||
"scrollToEnd" -> scrollToEnd(viewManager, scrollView, checkNotNull(args))
|
||||
"flashScrollIndicators" -> viewManager.flashScrollIndicators(scrollView)
|
||||
else ->
|
||||
throw IllegalArgumentException(
|
||||
"Unsupported command $commandType received by ${viewManager::class.java.simpleName}.")
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> scrollTo(
|
||||
viewManager: ScrollCommandHandler<T>,
|
||||
scrollView: T,
|
||||
args: ReadableArray
|
||||
) {
|
||||
val destX = Math.round(PixelUtil.toPixelFromDIP(args.getDouble(0)))
|
||||
val destY = Math.round(PixelUtil.toPixelFromDIP(args.getDouble(1)))
|
||||
val animated = args.getBoolean(2)
|
||||
viewManager.scrollTo(scrollView, ScrollToCommandData(destX, destY, animated))
|
||||
}
|
||||
|
||||
private fun <T> scrollToEnd(
|
||||
viewManager: ScrollCommandHandler<T>,
|
||||
scrollView: T,
|
||||
args: ReadableArray
|
||||
) {
|
||||
val animated = args.getBoolean(0)
|
||||
viewManager.scrollToEnd(scrollView, ScrollToEndCommandData(animated))
|
||||
}
|
||||
}
|
||||
|
||||
public interface ScrollCommandHandler<T> {
|
||||
public fun scrollTo(scrollView: T, data: ScrollToCommandData)
|
||||
|
||||
public fun scrollToEnd(scrollView: T, data: ScrollToEndCommandData)
|
||||
|
||||
public fun flashScrollIndicators(scrollView: T)
|
||||
}
|
||||
|
||||
public class ScrollToCommandData(
|
||||
@JvmField public val mDestX: Int,
|
||||
@JvmField public val mDestY: Int,
|
||||
@JvmField public val mAnimated: Boolean
|
||||
)
|
||||
|
||||
public class ScrollToEndCommandData(@JvmField public val mAnimated: Boolean)
|
||||
}
|
||||
Reference in New Issue
Block a user