From d382b23901f15938d4f3338b21e403b3289a5bf3 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Mon, 10 Aug 2015 10:15:43 -0400 Subject: [PATCH] app: plumb through iOS orientation Change-Id: I9cfaf23219a8e7e15727bd7338503b9fbc4634a2 Reviewed-on: https://go-review.googlesource.com/13444 Reviewed-by: Hyang-Ah Hana Kim --- app/darwin_armx.go | 15 ++++++++++++--- app/darwin_armx.m | 10 ++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/darwin_armx.go b/app/darwin_armx.go index 3639c7d..5a4f6d8 100644 --- a/app/darwin_armx.go +++ b/app/darwin_armx.go @@ -13,6 +13,7 @@ package app #include #include #include +#include extern struct utsname sysInfo; @@ -97,15 +98,23 @@ func setScreen(scale int) { } //export updateConfig -func updateConfig(width, height int) { - widthPx := screenScale * width - heightPx := screenScale * height +func updateConfig(width, height, orientation int32) { + o := config.OrientationUnknown + switch orientation { + case C.UIDeviceOrientationPortrait, C.UIDeviceOrientationPortraitUpsideDown: + o = config.OrientationPortrait + case C.UIDeviceOrientationLandscapeLeft, C.UIDeviceOrientationLandscapeRight: + o = config.OrientationLandscape + } + widthPx := screenScale * int(width) + heightPx := screenScale * int(height) eventsIn <- config.Event{ WidthPx: widthPx, HeightPx: heightPx, WidthPt: geom.Pt(float32(widthPx) / pixelsPerPt), HeightPt: geom.Pt(float32(heightPx) / pixelsPerPt), PixelsPerPt: pixelsPerPt, + Orientation: o, } } diff --git a/app/darwin_armx.m b/app/darwin_armx.m index c8ea451..c521bba 100644 --- a/app/darwin_armx.m +++ b/app/darwin_armx.m @@ -54,11 +54,17 @@ struct utsname sysInfo; setScreen(scale); CGSize size = [UIScreen mainScreen].bounds.size; - updateConfig((int)size.width, (int)size.height); + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + updateConfig((int)size.width, (int)size.height, orientation); } - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { - updateConfig((int)size.width, (int)size.height); + [coordinator animateAlongsideTransition:^(id context) { + // TODO(crawshaw): come up with a plan to handle animations. + } completion:^(id context) { + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + updateConfig((int)size.width, (int)size.height, orientation); + }]; } - (void)update {