mirror of
https://github.com/status-im/react-native.git
synced 2025-01-28 02:04:55 +00:00
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:
parent
5b0dd6432a
commit
3b68869fc8
@ -366,6 +366,26 @@ var ScrollResponderMixin = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like `scrollResponderScrollTo` but immediately scrolls to the given
|
||||||
|
* position
|
||||||
|
*/
|
||||||
|
scrollResponderScrollWithouthAnimationTo: function(offsetX: number, offsetY: number) {
|
||||||
|
if (Platform.OS === 'android') {
|
||||||
|
RCTUIManager.dispatchViewManagerCommand(
|
||||||
|
React.findNodeHandle(this),
|
||||||
|
RCTUIManager.RCTScrollView.Commands.scrollWithoutAnimationTo,
|
||||||
|
[offsetX, offsetY],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
RCTUIManager.scrollWithoutAnimationTo(
|
||||||
|
React.findNodeHandle(this),
|
||||||
|
offsetX,
|
||||||
|
offsetY
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper function to zoom to a specific rect in the scrollview.
|
* A helper function to zoom to a specific rect in the scrollview.
|
||||||
* @param {object} rect Should have shape {x, y, width, height}
|
* @param {object} rect Should have shape {x, y, width, height}
|
||||||
|
@ -290,10 +290,10 @@ var ScrollView = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
scrollWithoutAnimationTo: function(destY?: number, destX?: number) {
|
scrollWithoutAnimationTo: function(destY?: number, destX?: number) {
|
||||||
RCTUIManager.scrollWithoutAnimationTo(
|
// $FlowFixMe - Don't know how to pass Mixin correctly. Postpone for now
|
||||||
React.findNodeHandle(this),
|
this.getScrollResponder().scrollResponderScrollWithouthAnimationTo(
|
||||||
destX || 0,
|
destX || 0,
|
||||||
destY || 0
|
destY || 0,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -51,4 +51,11 @@ public class ReactHorizontalScrollViewManager
|
|||||||
ReactScrollViewCommandHelper.ScrollToCommandData data) {
|
ReactScrollViewCommandHelper.ScrollToCommandData data) {
|
||||||
scrollView.smoothScrollTo(data.mDestX, data.mDestY);
|
scrollView.smoothScrollTo(data.mDestX, data.mDestY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scrollWithoutAnimationTo(
|
||||||
|
ReactHorizontalScrollView scrollView,
|
||||||
|
ReactScrollViewCommandHelper.ScrollToCommandData data) {
|
||||||
|
scrollView.scrollTo(data.mDestX, data.mDestY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,11 @@ import com.facebook.react.common.MapBuilder;
|
|||||||
public class ReactScrollViewCommandHelper {
|
public class ReactScrollViewCommandHelper {
|
||||||
|
|
||||||
public static final int COMMAND_SCROLL_TO = 1;
|
public static final int COMMAND_SCROLL_TO = 1;
|
||||||
|
public static final int COMMAND_SCROLL_WITHOUT_ANIMATION_TO = 2;
|
||||||
|
|
||||||
public interface ScrollCommandHandler<T> {
|
public interface ScrollCommandHandler<T> {
|
||||||
void scrollTo(T scrollView, ScrollToCommandData data);
|
void scrollTo(T scrollView, ScrollToCommandData data);
|
||||||
|
void scrollWithoutAnimationTo(T scrollView, ScrollToCommandData data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ScrollToCommandData {
|
public static class ScrollToCommandData {
|
||||||
@ -41,7 +43,11 @@ public class ReactScrollViewCommandHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String,Integer> getCommandsMap() {
|
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(
|
public static <T> void receiveCommand(
|
||||||
@ -53,11 +59,18 @@ public class ReactScrollViewCommandHelper {
|
|||||||
Assertions.assertNotNull(scrollView);
|
Assertions.assertNotNull(scrollView);
|
||||||
Assertions.assertNotNull(args);
|
Assertions.assertNotNull(args);
|
||||||
switch (commandType) {
|
switch (commandType) {
|
||||||
case COMMAND_SCROLL_TO:
|
case COMMAND_SCROLL_TO: {
|
||||||
int destX = Math.round(PixelUtil.toPixelFromDIP(args.getInt(0)));
|
int destX = Math.round(PixelUtil.toPixelFromDIP(args.getInt(0)));
|
||||||
int destY = Math.round(PixelUtil.toPixelFromDIP(args.getInt(1)));
|
int destY = Math.round(PixelUtil.toPixelFromDIP(args.getInt(1)));
|
||||||
viewManager.scrollTo(scrollView, new ScrollToCommandData(destX, destY));
|
viewManager.scrollTo(scrollView, new ScrollToCommandData(destX, destY));
|
||||||
return;
|
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:
|
default:
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new IllegalArgumentException(String.format(
|
||||||
"Unsupported command %d received by %s.",
|
"Unsupported command %d received by %s.",
|
||||||
|
@ -84,6 +84,13 @@ public class ReactScrollViewManager
|
|||||||
scrollView.smoothScrollTo(data.mDestX, data.mDestY);
|
scrollView.smoothScrollTo(data.mDestX, data.mDestY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scrollWithoutAnimationTo(
|
||||||
|
ReactScrollView scrollView,
|
||||||
|
ReactScrollViewCommandHelper.ScrollToCommandData data) {
|
||||||
|
scrollView.scrollTo(data.mDestX, data.mDestY);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Map getExportedCustomDirectEventTypeConstants() {
|
public @Nullable Map getExportedCustomDirectEventTypeConstants() {
|
||||||
return MapBuilder.builder()
|
return MapBuilder.builder()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user