Add scrollWithoutAnimationTo to Android

Summary: `ScrollView.scrollWithoutAnimationTo` is supported on iOS but not Android. This is an existing API, and this diff adds Android support.

Closes https://github.com/facebook/react-native/pull/2695

Reviewed By: @​svcscm

Differential Revision: D2452630

Pulled By: @mkonicek
This commit is contained in:
James Ide
2015-09-23 05:57:00 -07:00
committed by facebook-github-bot-7
parent 5b0dd6432a
commit 3b68869fc8
5 changed files with 52 additions and 5 deletions

View File

@@ -51,4 +51,11 @@ public class ReactHorizontalScrollViewManager
ReactScrollViewCommandHelper.ScrollToCommandData data) {
scrollView.smoothScrollTo(data.mDestX, data.mDestY);
}
@Override
public void scrollWithoutAnimationTo(
ReactHorizontalScrollView scrollView,
ReactScrollViewCommandHelper.ScrollToCommandData data) {
scrollView.scrollTo(data.mDestX, data.mDestY);
}
}

View File

@@ -25,9 +25,11 @@ import com.facebook.react.common.MapBuilder;
public class ReactScrollViewCommandHelper {
public static final int COMMAND_SCROLL_TO = 1;
public static final int COMMAND_SCROLL_WITHOUT_ANIMATION_TO = 2;
public interface ScrollCommandHandler<T> {
void scrollTo(T scrollView, ScrollToCommandData data);
void scrollWithoutAnimationTo(T scrollView, ScrollToCommandData data);
}
public static class ScrollToCommandData {
@@ -41,7 +43,11 @@ public class ReactScrollViewCommandHelper {
}
public static Map<String,Integer> getCommandsMap() {
return MapBuilder.of("scrollTo", COMMAND_SCROLL_TO);
return MapBuilder.of(
"scrollTo",
COMMAND_SCROLL_TO,
"scrollWithoutAnimationTo",
COMMAND_SCROLL_WITHOUT_ANIMATION_TO);
}
public static <T> void receiveCommand(
@@ -53,11 +59,18 @@ public class ReactScrollViewCommandHelper {
Assertions.assertNotNull(scrollView);
Assertions.assertNotNull(args);
switch (commandType) {
case COMMAND_SCROLL_TO:
case COMMAND_SCROLL_TO: {
int destX = Math.round(PixelUtil.toPixelFromDIP(args.getInt(0)));
int destY = Math.round(PixelUtil.toPixelFromDIP(args.getInt(1)));
viewManager.scrollTo(scrollView, new ScrollToCommandData(destX, destY));
return;
}
case COMMAND_SCROLL_WITHOUT_ANIMATION_TO: {
int destX = Math.round(PixelUtil.toPixelFromDIP(args.getInt(0)));
int destY = Math.round(PixelUtil.toPixelFromDIP(args.getInt(1)));
viewManager.scrollWithoutAnimationTo(scrollView, new ScrollToCommandData(destX, destY));
return;
}
default:
throw new IllegalArgumentException(String.format(
"Unsupported command %d received by %s.",

View File

@@ -84,6 +84,13 @@ public class ReactScrollViewManager
scrollView.smoothScrollTo(data.mDestX, data.mDestY);
}
@Override
public void scrollWithoutAnimationTo(
ReactScrollView scrollView,
ReactScrollViewCommandHelper.ScrollToCommandData data) {
scrollView.scrollTo(data.mDestX, data.mDestY);
}
@Override
public @Nullable Map getExportedCustomDirectEventTypeConstants() {
return MapBuilder.builder()