Skip to content

Commit 1dac79d

Browse files
authored
fix(android): initial gesture orientation value (#13755)
* fix(android): initial gesture orientation value * docs
1 parent 4add280 commit 1dac79d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

android/modules/gesture/src/java/ti/modules/titanium/gesture/GestureModule.java

+16
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
importorg.appcelerator.titanium.ContextSpecific;
1515
importorg.appcelerator.titanium.TiApplication;
1616
importorg.appcelerator.titanium.TiProperties;
17+
importorg.appcelerator.titanium.util.TiDeviceOrientation;
1718
importorg.appcelerator.titanium.util.TiSensorHelper;
1819

20+
importandroid.content.res.Configuration;
1921
importandroid.hardware.Sensor;
2022
importandroid.hardware.SensorEvent;
2123
importandroid.hardware.SensorEventListener;
@@ -174,12 +176,20 @@ public void onSensorChanged(SensorEvent event)
174176
@Kroll.getProperty
175177
publicbooleangetPortrait()
176178
{
179+
if (this.deviceOrientationMonitor.getLastReadOrientation() == TiDeviceOrientation.UNKNOWN) {
180+
intorientation = TiApplication.getAppCurrentActivity().getResources().getConfiguration().orientation;
181+
returnorientation == Configuration.ORIENTATION_PORTRAIT;
182+
}
177183
returnthis.deviceOrientationMonitor.getLastReadOrientation().isPortrait();
178184
}
179185

180186
@Kroll.getProperty
181187
publicbooleangetLandscape()
182188
{
189+
if (this.deviceOrientationMonitor.getLastReadOrientation() == TiDeviceOrientation.UNKNOWN) {
190+
intorientation = TiApplication.getAppCurrentActivity().getResources().getConfiguration().orientation;
191+
returnorientation == Configuration.ORIENTATION_LANDSCAPE;
192+
}
183193
returnthis.deviceOrientationMonitor.getLastReadOrientation().isLandscape();
184194
}
185195

@@ -189,6 +199,12 @@ public int getOrientation()
189199
returnthis.deviceOrientationMonitor.getLastReadOrientation().toTiIntId();
190200
}
191201

202+
@Kroll.method
203+
publicvoidstopListener()
204+
{
205+
this.deviceOrientationMonitor.stop();
206+
}
207+
192208
@Override
193209
publicStringgetApiName()
194210
{

apidoc/Titanium/Gesture/Gesture.yml

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ properties:
4444
type: Number
4545
permission: read-only
4646

47+
methods:
48+
- name: stopListener
49+
summary: Stops the gesture listener.
50+
description: |
51+
In case you use `Titanium.Gesture.landscape` or `Titanium.Gesture.portrait` it will attach the orientation
52+
listener automatically. If you just use it once you can use this method to stop the listener.
53+
since: "12.1.0"
54+
platforms: [android]
55+
4756
events:
4857
- name: orientationchange
4958
summary: Fired when the device orientation changes.

0 commit comments

Comments
 (0)
close