Support scrollTo with RecycleViewBackedScrollView.
Differential Revision: D2581381 fb-gh-sync-id: 830f36f4d62a3097fdf3697a94a22441f11f93ef
This commit is contained in:
parent
d4eb8201f1
commit
cf35f47c4d
|
@ -223,26 +223,37 @@ public class RecyclerViewBackedScrollView extends RecyclerView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private int calculateAbsoluteOffset() {
|
||||||
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
|
|
||||||
super.onScrollChanged(l, t, oldl, oldt);
|
|
||||||
|
|
||||||
ReactListAdapter adapter = (ReactListAdapter) getAdapter();
|
|
||||||
|
|
||||||
int offsetY = 0;
|
int offsetY = 0;
|
||||||
if (getChildCount() > 0) {
|
if (getChildCount() > 0) {
|
||||||
View recyclerViewChild = getChildAt(0);
|
View recyclerViewChild = getChildAt(0);
|
||||||
int childPosition = getChildAdapterPosition(recyclerViewChild);
|
int childPosition = getChildAdapterPosition(recyclerViewChild);
|
||||||
offsetY = adapter.getTopOffsetForItem(childPosition) - recyclerViewChild.getTop();
|
offsetY = ((ReactListAdapter) getAdapter()).getTopOffsetForItem(childPosition) -
|
||||||
|
recyclerViewChild.getTop();
|
||||||
}
|
}
|
||||||
|
return offsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*package*/ void scrollTo(int scrollX, int scrollY, boolean animated) {
|
||||||
|
int deltaY = scrollY - calculateAbsoluteOffset();
|
||||||
|
if (animated) {
|
||||||
|
smoothScrollBy(0, deltaY);
|
||||||
|
} else {
|
||||||
|
scrollBy(0, deltaY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
|
||||||
|
super.onScrollChanged(l, t, oldl, oldt);
|
||||||
|
|
||||||
ScrollEvent event = new ScrollEvent(
|
ScrollEvent event = new ScrollEvent(
|
||||||
getId(),
|
getId(),
|
||||||
SystemClock.uptimeMillis(),
|
SystemClock.uptimeMillis(),
|
||||||
0, /* offsetX = 0, horizontal scrolling only */
|
0, /* offsetX = 0, horizontal scrolling only */
|
||||||
offsetY,
|
calculateAbsoluteOffset(),
|
||||||
getWidth(),
|
getWidth(),
|
||||||
adapter.getTotalChildrenHeight(),
|
((ReactListAdapter) getAdapter()).getTotalChildrenHeight(),
|
||||||
getWidth(),
|
getWidth(),
|
||||||
getHeight());
|
getHeight());
|
||||||
((ReactContext) getContext()).getNativeModule(UIManagerModule.class).getEventDispatcher()
|
((ReactContext) getContext()).getNativeModule(UIManagerModule.class).getEventDispatcher()
|
||||||
|
|
|
@ -2,16 +2,21 @@
|
||||||
|
|
||||||
package com.facebook.react.views.recyclerview;
|
package com.facebook.react.views.recyclerview;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.facebook.react.bridge.ReadableArray;
|
||||||
import com.facebook.react.uimanager.ThemedReactContext;
|
import com.facebook.react.uimanager.ThemedReactContext;
|
||||||
import com.facebook.react.uimanager.ViewGroupManager;
|
import com.facebook.react.uimanager.ViewGroupManager;
|
||||||
|
import com.facebook.react.views.scroll.ReactScrollViewCommandHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View manager for {@link RecyclerViewBackedScrollView}.
|
* View manager for {@link RecyclerViewBackedScrollView}.
|
||||||
*/
|
*/
|
||||||
public class RecyclerViewBackedScrollViewManager extends
|
public class RecyclerViewBackedScrollViewManager extends
|
||||||
ViewGroupManager<RecyclerViewBackedScrollView> {
|
ViewGroupManager<RecyclerViewBackedScrollView>
|
||||||
|
implements ReactScrollViewCommandHelper.ScrollCommandHandler<RecyclerViewBackedScrollView> {
|
||||||
|
|
||||||
private static final String REACT_CLASS = "AndroidRecyclerViewBackedScrollView";
|
private static final String REACT_CLASS = "AndroidRecyclerViewBackedScrollView";
|
||||||
|
|
||||||
|
@ -46,4 +51,29 @@ public class RecyclerViewBackedScrollViewManager extends
|
||||||
public void removeView(RecyclerViewBackedScrollView parent, View child) {
|
public void removeView(RecyclerViewBackedScrollView parent, View child) {
|
||||||
parent.removeViewFromAdapter(child);
|
parent.removeViewFromAdapter(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides implementation of commands supported by {@link ReactScrollViewManager}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void receiveCommand(
|
||||||
|
RecyclerViewBackedScrollView view,
|
||||||
|
int commandId,
|
||||||
|
@Nullable ReadableArray args) {
|
||||||
|
ReactScrollViewCommandHelper.receiveCommand(this, view, commandId, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scrollTo(
|
||||||
|
RecyclerViewBackedScrollView view,
|
||||||
|
ReactScrollViewCommandHelper.ScrollToCommandData data) {
|
||||||
|
view.scrollTo(data.mDestX, data.mDestY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scrollWithoutAnimationTo(
|
||||||
|
RecyclerViewBackedScrollView view,
|
||||||
|
ReactScrollViewCommandHelper.ScrollToCommandData data) {
|
||||||
|
view.scrollTo(data.mDestX, data.mDestY, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue