Skip to content

feat: android notch wrapper #3591

@CrisPRuz

Description

@CrisPRuz

I'm submitting a ... (check one with "x")
[ ] bug report
[X] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://ionicworldwide.herokuapp.com/

Current behavior:
Some Android devices, such as Samsung Galaxy S10, have a cutout or notch (e.g. because of their front camera). However, there is any wrapper for cordova-plugin-android-notch that could be use in Ionic projects.

Expected behavior:

I have decide to develop a wrapper from the above cordova plugin and I would like to submit a PR with the code. For instance, It could be used to apply certain styles (e.g. modify css custom properties)

Steps to reproduce:

To test the wrapper, it is possible to do it using Ionic webpage examples and guidelines for setting up a project:

  1. Create a new Ionic project with Angular (Ionic webpage guidelines might be used).
  2. Install the cordova plugin in your project:
ionic cordova plugin add cordova-plugin-android-notch
  1. Install the wrapper
  2. Install Android Studio and configure its environmental variables following the guidelines.
  3. Set up a virtual device and its notch (unblock developer options in the device is needed).
  4. See Related code section to examples of use.

Related code:

  1. Import the dependency
import { AndroidNotch } from "@ionic-native/android-notch/ngx";
  1. Add it to your provides list at the module config
providers: [AndroidNotch] 
  1. Add it in the class you want to use it
constructor(private androidNotch: AndroidNotch) {}
  1. Wrapper use examples:
this.platform.ready().then(() => {
      this.androidNotch.hasCutout().then(
        (hasCutout: boolean) => console.log('hasCutout: ',hasCutout),
        (err: any) => console.error("Failed to get cutout", err)
      );

     this.androidNotch.getInsetTop().then(
        (px: number) => console.log('getInsetTop: ',px),
        (err: any) => console.error("Failed to get insets top:", err)
      );

      this.androidNotch.getInsetRight().then(
        (px: number) => console.log('getInsetRight: ',px),
        (err: any) => console.error("Failed to get insets right:", err)
      );

      this.androidNotch.getInsetBottom().then(
        (px: number) => console.log('getInsetBottom: ',px),
        (err: any) => console.error("Failed to get insets bottom:", err)
      );

      this.androidNotch.getInsetLeft().then(
        (px: number) => console.log('getInsetLeft: ', px),
        (err: any) => console.error("Failed to get insets left:", err)
      );
});

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):


Ionic:

   Ionic CLI : 6.12.2

Utility:

   cordova-res : 0.15.2
   native-run  : 1.3.0

System:

   NodeJS : v12.18.3
   npm    : 6.14.9

See submited PR.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions