mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support commands as strings in ScrollView
Summary: See https://github.com/facebook/react-native/commit/3cae6fa950eed54bccccf61a28c0e85d5a004c6c for more context Reviewed By: JoshuaGross Differential Revision: D16011124 fbshipit-source-id: bd402773aafc4682d4d1570cf7dbb295044b0fa7
This commit is contained in:
committed by
Facebook Github Bot
parent
faf5c0b5ef
commit
ac87b0f6f3
+8
@@ -168,6 +168,14 @@ public class ReactHorizontalScrollViewManager
|
||||
ReactScrollViewCommandHelper.receiveCommand(this, scrollView, commandId, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveCommand(
|
||||
ReactHorizontalScrollView scrollView,
|
||||
String commandId,
|
||||
@Nullable ReadableArray args) {
|
||||
ReactScrollViewCommandHelper.receiveCommand(this, scrollView, commandId, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashScrollIndicators(ReactHorizontalScrollView scrollView) {
|
||||
scrollView.flashScrollIndicators();
|
||||
|
||||
+47
-6
@@ -71,15 +71,11 @@ public class ReactScrollViewCommandHelper {
|
||||
Assertions.assertNotNull(args);
|
||||
switch (commandType) {
|
||||
case COMMAND_SCROLL_TO: {
|
||||
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));
|
||||
scrollTo(viewManager, scrollView, args);
|
||||
return;
|
||||
}
|
||||
case COMMAND_SCROLL_TO_END: {
|
||||
boolean animated = args.getBoolean(0);
|
||||
viewManager.scrollToEnd(scrollView, new ScrollToEndCommandData(animated));
|
||||
scrollToEnd(viewManager, scrollView, args);
|
||||
return;
|
||||
}
|
||||
case COMMAND_FLASH_SCROLL_INDICATORS:
|
||||
@@ -93,4 +89,49 @@ public class ReactScrollViewCommandHelper {
|
||||
viewManager.getClass().getSimpleName()));
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void receiveCommand(
|
||||
ScrollCommandHandler<T> viewManager,
|
||||
T scrollView,
|
||||
String commandType,
|
||||
@Nullable ReadableArray args) {
|
||||
Assertions.assertNotNull(viewManager);
|
||||
Assertions.assertNotNull(scrollView);
|
||||
Assertions.assertNotNull(args);
|
||||
switch (commandType) {
|
||||
case "scrollTo": {
|
||||
scrollTo(viewManager, scrollView, args);
|
||||
return;
|
||||
}
|
||||
case "scrollToEnd": {
|
||||
scrollToEnd(viewManager, scrollView, 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, @Nullable 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, @Nullable ReadableArray args) {
|
||||
boolean animated = args.getBoolean(0);
|
||||
viewManager.scrollToEnd(scrollView, new ScrollToEndCommandData(animated));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +185,14 @@ public class ReactScrollViewManager
|
||||
ReactScrollViewCommandHelper.receiveCommand(this, scrollView, commandId, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveCommand(
|
||||
ReactScrollView scrollView,
|
||||
String commandId,
|
||||
@Nullable ReadableArray args) {
|
||||
ReactScrollViewCommandHelper.receiveCommand(this, scrollView, commandId, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flashScrollIndicators(ReactScrollView scrollView) {
|
||||
scrollView.flashScrollIndicators();
|
||||
|
||||
Reference in New Issue
Block a user