Skip to content

Commit 040e09e

Browse files
Force orientation change on iOS lockOrientation (#4251)
Initial attempt on #3209 but it isn't working yet.
1 parent d4000ed commit 040e09e

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

Ports/iOSPort/nativeSources/IOSNative.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,8 +1982,24 @@ void com_codename1_impl_ios_IOSNative_lockOrientation___boolean(CN1_THREAD_STATE
19821982
//XMLVM_BEGIN_WRAPPER[com_codename1_impl_ios_IOSNative_lockOrientation___boolean]
19831983
if(n1) {
19841984
orientationLock = 1;
1985+
dispatch_async(dispatch_get_main_queue(), ^{
1986+
UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
1987+
if (currentOrientation != UIInterfaceOrientationPortrait && currentOrientation != UIInterfaceOrientationPortraitUpsideDown) {
1988+
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
1989+
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
1990+
[UIViewController attemptRotationToDeviceOrientation];
1991+
}
1992+
});
19851993
} else {
19861994
orientationLock = 2;
1995+
dispatch_async(dispatch_get_main_queue(), ^{
1996+
UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
1997+
if (currentOrientation != UIInterfaceOrientationLandscapeLeft && currentOrientation != UIInterfaceOrientationLandscapeRight) {
1998+
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
1999+
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
2000+
[UIViewController attemptRotationToDeviceOrientation];
2001+
}
2002+
});
19872003
}
19882004
//XMLVM_END_WRAPPER
19892005
}

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunner.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public final class Cn1ssDeviceRunner extends DeviceRunner {
6464
new TransformCamera(),
6565
new BrowserComponentScreenshotTest(),
6666
new MediaPlaybackScreenshotTest(),
67+
new OrientationLockScreenshotTest(),
6768
new InPlaceEditViewTest(),
6869
new AccessibilityTest()
6970
};
@@ -93,10 +94,10 @@ public void runSuite() {
9394
t.printStackTrace();
9495
}
9596
});
96-
int timeout = 9000;
97+
int timeout = 30000;
9798
while (!testClass.isDone() && timeout > 0) {
9899
Util.sleep(3);
99-
timeout--;
100+
timeout -= 3;
100101
}
101102
testClass.cleanup();
102103
if(timeout == 0) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.codenameone.examples.hellocodenameone.tests;
2+
3+
import com.codename1.testing.TestUtils;
4+
import com.codename1.ui.CN;
5+
import com.codename1.ui.Form;
6+
import com.codename1.ui.Label;
7+
import com.codename1.ui.layouts.BoxLayout;
8+
import com.codename1.ui.util.UITimer;
9+
10+
public class OrientationLockScreenshotTest extends BaseTest {
11+
@Override
12+
public boolean runTest() throws Exception {
13+
Form hi = createForm("Orientation Lock", new BoxLayout(BoxLayout.Y_AXIS), "landscape");
14+
hi.add(new Label("Testing orientation lock..."));
15+
16+
hi.show();
17+
18+
CN.lockOrientation(false);
19+
20+
TestUtils.waitFor(250);
21+
22+
return true;
23+
}
24+
}

0 commit comments

Comments
 (0)