question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New ActionBar "flat" code doesn't support background-color: transparent on iOS

See original GitHub issue

This has been recently introduced in commit for #3900. While it’s a welcome step forward in CSS styling, it doesn’t work properly with ActionBar background color set to β€œtransparent” because translucent is always set to false, which renders β€œtransparent” as β€œblack”. On the other hand, setting translucent to true doesn’t render any color, so, it seems, β€œtransparent” background color needs special handling that’s not yet present.

Below is the test app and a screenshot. The expected result is that the action bar has the same background as the body.

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
    <Page.actionBar>
        <ActionBar title="My App" icon="" class="action-bar">
        </ActionBar>
    </Page.actionBar>
    <StackLayout class="p-20">
        <Label text="Tap the button" class="h1 text-center"/>
        <Button text="TAP" tap="{{ onTap }}" class="btn btn-primary btn-active"/>
        <Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
    </StackLayout>
</Page>
@import 'nativescript-theme-core/css/core.light.css';

.btn {
    font-size: 18;
}

.page {
    background-color: turquoise;
}

.action-bar {
    background-color: transparent;
    color: white;
    flat: true;
}
$ tns info

All NativeScript components versions information
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Component        β”‚ Current version β”‚ Latest version β”‚ Information   β”‚
β”‚ nativescript     β”‚ 3.1.3           β”‚ 3.1.3          β”‚ Up to date    β”‚
β”‚ tns-core-modules β”‚ 3.1.1           β”‚ 3.1.1          β”‚ Up to date    β”‚
β”‚ tns-android      β”‚                 β”‚ 3.1.1          β”‚ Not installed β”‚
β”‚ tns-ios          β”‚ 3.1.0           β”‚ 3.1.0          β”‚ Up to date    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

image

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
sserdyukcommented, Sep 16, 2017

@uzarsalan Here’s the code I’m using in production and it performs well in both iOS 9 and 10. I’m using it as a custom component. shared/widgets/transparentActionBar is the path to the file with the component. I’m overriding update() to apply my styling after NS is done applying the default. For more info see the docs http://docs.nativescript.org/ui/basics#custom-components

Component in shared/widgets/transparentActionBar:

import { ActionBar as BaseActionBar } from "ui/action-bar";

export class ActionBar extends BaseActionBar {
    private get navBar(): UINavigationBar {
        const page = this.page;
        // Page should be attached to frame to update the action bar.
        if (!page || !page.frame) {
            return undefined;
        }
        return (<UINavigationController>page.frame.ios.controller).navigationBar;
    }

    public update() {
        super.update();    
        let navBar = this.navBar;
        if (navBar) {
            navBar.barStyle = UIBarStyle.BlackTranslucent;
            navBar.setBackgroundImageForBarMetrics(UIImage.new(), UIBarMetrics.Default);
            navBar.shadowImage = UIImage.new();
            navBar.translucent = true;
        }
    }
}

XML:

<Page 
    xmlns="http://schemas.nativescript.org/tns.xsd" 
    xmlns:ab="shared/widgets/transparentActionBar"
>
  <ab:ActionBar title="123">
  </ab:ActionBar>
  <GridLayout rows="auto,*,auto,*,auto,auto,*">
   .....
  </GridLayout>
</Page>

CSS:

Page ActionBar {
  flat: true;
  background-color: transparent;
}
1reaction
alfrednerstucommented, Nov 26, 2018

@sserdyuk When you set the shadowImage to a new UIImage, translucency doesn’t work.

See this Stack Overflow thread: https://stackoverflow.com/questions/19226965/how-to-hide-uinavigationbar-1px-bottom-line/19227158#19227158

I’ve created a issue suggesting a way to remove the hairline border without affecting translucency here: https://github.com/NativeScript/NativeScript/issues/6620

Read more comments on GitHub >

github_iconTop Results From Across the Web

New ActionBar "flat" code doesn't support background-color
New ActionBar "flat" code doesn't support background-color: transparent on iOS.
Read more >
barTintColor not working in iOS 15 | Apple Developer Forums
Hi,. When I run the following code in application(_ :didFinishLaunchingWithOptions) in iOS 15, the bar color turns transparent (thus, showing the blackΒ ...
Read more >
NativeScript ActionBar Opacity - Stack Overflow
I try to change the opacity of the actionbar. For test i try to change the color over native method but this won't...
Read more >
How to Match a NativeScript ActionBar's Color on iOS
Luckily, getting the colors to match is relatively simple. The UINavigationBar has a translucent property that controls whether iOS uses theΒ ...
Read more >
Apply shadow or blur effects – Figma Help Center
Note: Inner shadows don't support show behind transparent areas. ... Background blur is used a lot for interactive menus in iOS. But you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found