Skip to content

ref(android): Cleanup and optimization for scroll view classes#10202

Closed
CatchABus wants to merge 9 commits intoNativeScript:mainfrom
CatchABus:android-scrollview-rework
Closed

ref(android): Cleanup and optimization for scroll view classes#10202
CatchABus wants to merge 9 commits intoNativeScript:mainfrom
CatchABus:android-scrollview-rework

Conversation

@CatchABus
Copy link
Copy Markdown
Contributor

@CatchABus CatchABus commented Feb 4, 2023

PR Checklist

What is the current behavior?

NativeScript scroll views are currently inheriting android NestedScrollView and HorizontalScrollView classes. This results in NativeScript horizontal and vertical scrollviews containing features that are already implemented by those classes mentioned above.

In addition, scroll view saved state has stopped working because of conflict problems. See #10200

What is the new behavior?

This patch gets rid of obsolete code and fixes open issue at the same time.
On top of that, scroll view classes will now call superclass onLayout which handles saved state restoration too.

@farfromrefug Your opinion is very important on this one.

Fixes/Closes #10200.

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Feb 4, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 38cded4. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@cla-bot cla-bot bot added the cla: yes label Feb 4, 2023
@CatchABus CatchABus marked this pull request as draft February 4, 2023 21:23
@farfromrefug
Copy link
Copy Markdown
Collaborator

@CatchABus I really like those changes. Looks much cleaner and efficient (all relying on NestedScrollView original behavior).
And personally I am ok with the breaking Change. Thanks for this !

@CatchABus
Copy link
Copy Markdown
Contributor Author

@CatchABus I really like those changes. Looks much cleaner and efficient (all relying on NestedScrollView original behavior). And personally I am ok with the breaking Change. Thanks for this !

Thank you very much! I've marked it as draft for now because iOS has center alignment as default so I'll look more into this.
I've managed to alter gravity defaults but centering needs improvements.

@farfromrefug
Copy link
Copy Markdown
Collaborator

@CatchABus and we can't have the child of the scrollview default android alignment set to center? That way it would not be a breaking change

@CatchABus
Copy link
Copy Markdown
Contributor Author

@farfromrefug I did a bit of work about that here: 462b993

It uses the gravity defaults we already had and applies result to scroll views until built-in layout is completed. In cases where scrollview nested layout has a fixed height but its children overlap, center alignment has still got different results but I think old behaviour was also different than that of iOS.

I believe this PR needs testing with more scenarios. Also, we should consider if it was less of a trouble to keep copies of those classes like we did before.
Feel free to post results or perform any changes that you see fit.

@CatchABus CatchABus marked this pull request as ready for review February 6, 2023 18:15
@CatchABus CatchABus force-pushed the android-scrollview-rework branch from 462b993 to f651443 Compare February 6, 2023 18:15
@jcassidyav
Copy link
Copy Markdown
Contributor

@CatchABus This looks great, but I am a little confused, does it contain a breaking change ? I do see differences in vertical alignment. ( Centering Vertically)

@CatchABus
Copy link
Copy Markdown
Contributor Author

@CatchABus This looks great, but I am a little confused, does it contain a breaking change ? I do see differences in vertical alignment. ( Centering Vertically)

I'm trying to imitate old layout behaviour as much as possible but patch might still be lacking few things.
Could you post your case? Screenshots should be good too.

@jcassidyav
Copy link
Copy Markdown
Contributor

New plain typescript app, wrap stackLayout in ScrollView i.e.

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
    <ActionBar title="My App" icon="" />
    <ScrollView >
    <StackLayout class="p-20">
        <Label text="Tap the button" class="h1 text-center" />
        <Button text="TAP" tap="{{ onTap }}" class="-primary" />
        <Label text="{{ message }}" class="h2 text-center" textWrap="true" />
    </StackLayout>
    </ScrollView>
</Page>

before:

with new:

@CatchABus CatchABus marked this pull request as draft February 7, 2023 22:51
@CatchABus
Copy link
Copy Markdown
Contributor Author

@jcassidyav I committed 2 fixes, one of which solves the problem you described.
Let me know if you see any other strange issue.

New changes have caused one of HorizontalScrollView tests to break so I'm still investigating a few things.

@jcassidyav
Copy link
Copy Markdown
Contributor

@CatchABus Another odd one, when a scroll view is used inside a @nativescript-community/ui-material-tabs , it no longer scrolls. No errors it just won't respond to a touch to scroll it.

e.g. https://stackblitz.com/edit/nativescript-stackblitz-templates-dgf6vd?file=app/main-page.xml

@CatchABus
Copy link
Copy Markdown
Contributor Author

CatchABus commented Feb 14, 2023

@farfromrefug @jcassidyav I close this in favor of #10213 . Layout rework gave me trouble because of how it currently works in {N} so I focused solely on exception fix.
We could retry this sometime in the future. Thank you very much for your assistance!

@CatchABus CatchABus closed this Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android][NS 8.4] Exception thrown when restoring state for ScrollView

3 participants