Skip to content

Commit

Permalink
fix(android): initial gesture orientation value (#13755)
Browse files Browse the repository at this point in the history
* fix(android): initial gesture orientation value

* docs
  • Loading branch information
m1ga committed Feb 24, 2023
1 parent 4add280 commit 1dac79d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.appcelerator.titanium.ContextSpecific;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiProperties;
import org.appcelerator.titanium.util.TiDeviceOrientation;
import org.appcelerator.titanium.util.TiSensorHelper;

import android.content.res.Configuration;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
Expand Down Expand Up @@ -174,12 +176,20 @@ public void onSensorChanged(SensorEvent event)
@Kroll.getProperty
public boolean getPortrait()
{
if (this.deviceOrientationMonitor.getLastReadOrientation() == TiDeviceOrientation.UNKNOWN) {
int orientation = TiApplication.getAppCurrentActivity().getResources().getConfiguration().orientation;
return orientation == Configuration.ORIENTATION_PORTRAIT;
}
return this.deviceOrientationMonitor.getLastReadOrientation().isPortrait();
}

@Kroll.getProperty
public boolean getLandscape()
{
if (this.deviceOrientationMonitor.getLastReadOrientation() == TiDeviceOrientation.UNKNOWN) {
int orientation = TiApplication.getAppCurrentActivity().getResources().getConfiguration().orientation;
return orientation == Configuration.ORIENTATION_LANDSCAPE;
}
return this.deviceOrientationMonitor.getLastReadOrientation().isLandscape();
}

Expand All @@ -189,6 +199,12 @@ public int getOrientation()
return this.deviceOrientationMonitor.getLastReadOrientation().toTiIntId();
}

@Kroll.method
public void stopListener()
{
this.deviceOrientationMonitor.stop();
}

@Override
public String getApiName()
{
Expand Down
9 changes: 9 additions & 0 deletions apidoc/Titanium/Gesture/Gesture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ properties:
type: Number
permission: read-only

methods:
- name: stopListener
summary: Stops the gesture listener.
description: |
In case you use `Titanium.Gesture.landscape` or `Titanium.Gesture.portrait` it will attach the orientation
listener automatically. If you just use it once you can use this method to stop the listener.
since: "12.1.0"
platforms: [android]

events:
- name: orientationchange
summary: Fired when the device orientation changes.
Expand Down

0 comments on commit 1dac79d

Please sign in to comment.