Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[iOS][Android] fix scrollToElement performance incorrect offset #2198

Merged
merged 5 commits into from
Mar 13, 2019

Conversation

win80540
Copy link
Contributor

@win80540 win80540 commented Mar 11, 2019

Since i start use Rax UI Framework - Nuke, i found i can't scroll to correct element on RTL layout.
Because Nuke will add a container div between scroller and scroller's child element.

ScrollToElement only can scroll to the direct child element on RTL direction in the online version,
now i fix the problem,scrollToElement can scroll to indirect child element.

BTW. i found scroll to begin let front-end engineer confused, now i found a better way to key offset when layout direction changed.

Nuke DEMO: https://jsplayground.taobao.org/raxplayground/5bf4b469-8eb1-4f5d-91df-912cd085ab7b
Direction chang DEMO:http://dotwe.org/vue/09cb6e35412f96c25c423fd50a929597

scrollToElement

@weex-bot
Copy link

weex-bot commented Mar 11, 2019

Fails
🚫 Failed to run assembleDebug task for android.
Messages
📖 android build verification finished.

Generated by 🚫 dangerJS

Copy link
Contributor

@YorkShen YorkShen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think code change in WXScroller.initComponentHostView may cause potential problem.

Your PR removes the code of @lucky-chen , you might as well contact him.

scrollView.post(new Runnable() {
@Override
public void run() {
if (mIslastDirectionRTL != null && isLayoutRTL() != mIslastDirectionRTL.booleanValue()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mIslastDirectionRTL is Boolean, which could cause null pointer exception here,

Why don't use boolean mIslastDirectionRTL directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if use boolean, default is false, is not what i want.
I need record direction when last layout change occur, it not always false, and i need distinct is layout change trigger first or not.

int width = right - left;
int changedWidth = width - oldWidth;
if (changedWidth != 0) {
scrollView.scrollBy(changedWidth, component.getScrollY());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing an else case, which could be a problem here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If changedWidth == 0, we should do nothing

scrollView.scrollTo(mw, component.getScrollY());
} else {
boolean scrollToBegin = true;
Object scrollToBeginOnLTR = getAttrs().get("scrollToBegin");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScrollBegin is added in #2165

Is there an reason to remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it do not scroll to begin anymore.

Copy link
Contributor

@YorkShen YorkShen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain the detail, pls

int totalWidth = getInnerView().getChildAt(0).getWidth();
int displayWidth = getInnerView().getMeasuredWidth();
viewXInScroller = totalWidth - (component.getAbsoluteX() - getAbsoluteX()) - displayWidth;
if (component.getParent() != null && component.getParent() == this) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to add this if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If hit this if, it mean's scroll to indirect child element, then the offsetX calculate will different from direct child element

Copy link
Contributor

@YorkShen YorkShen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Thanks to your contribute.

@YorkShen YorkShen merged commit c6f65a2 into apache:master Mar 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants