NathanaelA / nativescript-orientation

A NativeScript plugin to deal with Declarative UI and Screen Orientation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plugin causes double firing of resume event

NL33 opened this issue · comments

I've noticed a strange behavior. I have an app that has a resume event. If I add setOrientation to the resume event, the event fires twice. I have tested this several times and found it consistently to be the case on device.

Plugin version 2.2.1, NS version 5.3.1. Angular. iOS. On plugged in device.

Running with $ tns run ios --bundle...

service.ts:

var orientation = require('nativescript-orientation');
...
constructor(){
   applicationOn(suspendEvent, this.suspendEvent)
   applicationOn(resumeEvent, this.resumeEvent
}

suspendEvent = (args) =>{ }

resumeEvent = (args) => {
  orientation.setOrientation("portrait")  //THIS IS THE LINE THAT CAUSES RESUME EVENT TO FIRE TWICE
}

app.module.ts

 import { Service} from "~/app/service"
...
  constructor(private service: Service){
    this.service.resumeEvent
  }

If I include the orientation.setOrientation("portrait") in the service resume event, like above, the event fires twice if the app is resumed from landscape mode. So, if the phone is in landscape mode when the app resumes, and the setOrientation line is there, the resume event fires twice.

It only fires once if the setOrientation line is not there.

@NathanaelA, I know you are focused on the proplugins version, but this seems to be an odd mystery.

Why might this happen?

That is an odd mystery. If you can clone this repo and take the nativescript core demo and add your code and duplicate the issue; send me the URL and I'll look into it. 😀

Thanks. I haven't setup up a sample project yet, but have it as a to do.