Skip to content

Canvas will not render on Android when app is coming from background #67

@richardwalander

Description

@richardwalander

Im trying to create a new iOS type "squircle"-shaped buttons in one project and came up with the idea to draw the the curves using some kind of custom paint and found this plugin. I managed to create a custom layout using a flexbox as base and then the canvas for the left/right side of the button. I also use the canvas to draw the icon based on the SVG-path since I would like to change color programmatically. Here is a version of my template:

<StackLayout padding="100 50">
  <FlexboxLayout>
    <Canvas ref="left" width="22" height="44" @ready="renderLeft"></Canvas>
    <FlexboxLayout
      ref="center"
      alignSelf="stretch"
      flexGrow="2"
      alignItems="center"
      justifyContent="center"
      @loaded="renderCenter"
    >
      <Canvas
        id="icon"
        width="24"
        height="24"
        marginRight="8"
        @ready="renderIcon"
      ></Canvas>
      <Label text="Label" textAlignment="center" color="#ffffff"></Label>
    </FlexboxLayout>
    <Canvas id="right" width="22" height="44" @ready="renderRight"></Canvas>
  </FlexboxLayout>
</StackLayout>

Everything is working fine on iOS. The button render like it's supposed to:

image

On my real Android device the button render the first time you launch the app, but if you suspend it and then open it from running in the background the canvas will not render. It works on my Android emulator it renders but with a small delay but on my real device it will not render at all.

On first launch of app:

image

When coming back from background:

image

I have tried to generate both a angular and a vue project and have got the same result on both.

Here are my dependencies in the vue project:

"dependencies": {
    "@nativescript/canvas": "1.0.0-alpha.2",
    "@nativescript/core": "~8.0.0",
    "@nativescript/theme": "~3.0.1",
    "nativescript-vue": "~2.9.0"
  },
  "devDependencies": {
    "@nativescript/android": "8.0.0",
    "@nativescript/ios": "8.0.0",
    "@nativescript/webpack": "beta",
    "nativescript-vue-template-compiler": "~2.9.0",
    "sass": "^1.32.8"
  },

Here are my dependencies in the angular project:

"dependencies": {
    "@angular/animations": "~12.0.0",
    "@angular/common": "~12.0.0",
    "@angular/compiler": "~12.0.0",
    "@angular/core": "~12.0.0",
    "@angular/forms": "~12.0.0",
    "@angular/platform-browser": "~12.0.0",
    "@angular/platform-browser-dynamic": "~12.0.0",
    "@angular/router": "~12.0.0",
    "@nativescript/angular": "~12.0.0",
    "@nativescript/canvas": "^1.0.0-alpha.2",
    "@nativescript/core": "~8.0.0",
    "@nativescript/theme": "~3.0.1",
    "rxjs": "^6.6.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~12.0.0",
    "@nativescript/android": "8.0.0",
    "@nativescript/ios": "8.0.0",
    "@nativescript/types": "~8.0.0",
    "@nativescript/webpack": "beta",
    "@ngtools/webpack": "~12.0.0",
    "typescript": "~4.2.0"
  },

I don't know why it stops working when coming from the background. It feels like the UI re-renders but that the "ready" event stops firing or something. It's the same behaviour on both angular and vue. It's only on real device also a OnePlus Nord2 5G running Android 11.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions