Skip to content

fix(android-tabs): tab backgroundColor cache can be wrong - DO NOT MERGE#8510

Closed
NathanaelA wants to merge 9 commits into
NativeScript:masterfrom
NathanaelA:tab-backgrounds
Closed

fix(android-tabs): tab backgroundColor cache can be wrong - DO NOT MERGE#8510
NathanaelA wants to merge 9 commits into
NativeScript:masterfrom
NathanaelA:tab-backgrounds

Conversation

@NathanaelA
Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

  1. Currently on android if you set the Tab & TabView's background color; it cache's the color when you leave the page and resets it when you return to the page. (Good behavior so far). However, if you navigate away; and then change the global CSS from say light theme to a dark theme, then return back to the page with a tab/tab-view the tab attempts to use the old cached color, despite the CSS system passing a new backgroundColor into the control on refresh.

  2. On tab-views; the ViewPager can cache the background color; so we need to force it to change the color also.

  3. Crashing issue with updateAndroidItemAt during startup of control.

What is the new behavior?

  1. This clears the _originalBackground cached value if a new backgroundColor is set.

  2. sets the viewPagers color also

  3. Adds a safety check to make sure updateAndroidItemAt can't update something that doesn't exist.

Fixes/Implements/Closes #
Fixes two issues repoted in NativeScript-Themes repo with the "tabs" and "tab-view" controls.

@cla-bot cla-bot Bot added the cla: yes label Apr 7, 2020

if (value instanceof Color) {
this._tabLayout.setBackgroundColor(value.android);
this._viewPager.setBackgroundColor(value.android);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We shouldn't set the background color of the viewPager here as this should change only the background of the tab bar, but not the tab page as well. You can check the following page in the UI test project - https://github.com/NativeScript/NativeScript/blob/master/e2e/ui-tests-app/app/tab-view/all-page.xml

This comment was marked as abuse.


public updateAndroidItemAt(index: number, spec: org.nativescript.widgets.TabItemSpec) {
this._tabsBar.updateItemAt(index, spec);
if (index < this._tabsBar.getItemCount()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

}

public setTabBarBackgroundColor(value: android.graphics.drawable.Drawable | Color): void {
this._originalBackground = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment was marked as abuse.

@vtrifonov
Copy link
Copy Markdown
Contributor

@NathanaelA did you have a chance to view the comments?

@NathanaelA

This comment was marked as abuse.

@vtrifonov
Copy link
Copy Markdown
Contributor

@NathanaelA you can use e2e/ui-tests-app as an example app.

@NathanaelA

This comment was marked as abuse.

@cjohn001
Copy link
Copy Markdown

@NathanaelA
I have seen that you have already partly implemented a fix for the issue. As the issue seems to be a difficult one, and as it is somewhat older already, I was wondering, if you might recommend a workaround for it as long as the bug is open.The bug (background lost and white bg instead) appears for me if I use a goBack navigation which goes back to a tab view. Is there a way I could force to refresh the background on the tab control before it is rendered? Thank you very much for your help!

Best regards,
Christoph

@NathanaelA

This comment was marked as abuse.

@cjohn001
Copy link
Copy Markdown

cjohn001 commented Aug 21, 2020

@NathanaelA ,
thank you very much for the directions!

  • Could you maybe send me a link to an example on how I can store/restore the background? I have unfortunately never seen how one can do this. I am using NS Angular. Which lifecycle hooks would I have to use here? I tried out the following code, but without success. If I return to the page the background stays white, even so the loaded function is called and I set the color.

@HostListener('loaded')
pageInit() {
const backgroundGrid = this._pageBackgroundGrid.nativeElement as GridLayout;
backgroundGrid.style.backgroundColor = new Color('red');
}

  • I am not sure if it is related to this bug. But I currently run into problems with a couple of controls (ui chart, ui calendar) loosing their styles on IOS when the app leaves the background / resumes from background, or after the screensaver was activated. The controls then appear with the default styles rather than the ones set via palettes or a style service. The bugs are documented in the following issues, and I have not found a way yet, to redraw the controls before they appear on screen with the wrong styles. Currently, I am using the loaded event of the controls to force a refresh through resetting their data. But this is too late in the livecycle of the controls. When the app resumes the user sees the controls with the wrong styles for about half a second. Maybe the approach you described would be the right workaround as well?

#8775
ProgressNS/nativescript-ui-feedback#1335

Are these issues related to the same underlaying problem we are dealing with here?

  • Final question: Are you currently working on this issue and I can expect a fix soon. Then I would proceed with other parts in my app development till the fix is there. But nevertheless it would be great if you could explain the way to store the css. It might help me at least with the other bugs.

If I can help with testing, please let me know. And thank you very much for your support.

Best regards,
Christoph

@NathanWalker
Copy link
Copy Markdown
Contributor

NathanWalker commented Oct 27, 2020

Further investigation into property (and CSS in general) handling will be done separately.

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.

4 participants