flowkey / UIKit-cross-platform

Cross-platform Swift implementation of UIKit, mostly for Android
MIT License
597 stars 40 forks source link

properties in CGSize extension that enable forcing a portrait/landscape orientation #239

Closed janek closed 6 years ago

janek commented 6 years ago

Type of change: feature

Motivation

We should probably default to vertical, but we should also definitely have an easy/familiar way of switching orientation. This would be a first step.

michaelknoch commented 6 years ago

Good point @janekszynal ! I think we should definitely enable rendering apps in portrait before we release UIKit. Im not sure which changes are actually required to make this possible. I think an important part is located here.

I think dynamic orientation is not going to happen in our first releasable version, because the android system kills the whole surface context when orientation changes from portrait to landscape or vice versa. It would be possible to save the context and restore ist, but @ephemer mentioned this as a very tough task. Having an app with locked orientation in landscape or portrait should be possible without any major refactors and I think its very desirable for the release.

janek commented 6 years ago

thanks @michaelknoch!

actual dynamic orientation would def be great to have. What I meant was just making it easier to switch between portrait/landscape from code, for now (may have been a bit unclear, I now realise).

we currently have 7-8 frames defined, all of which are dimensions of Android models in landscape. In this PR I add helper functions that allow you to use the existing frames, but easily making them .vertical() or explicitly .horizontal() (for potential future use)

michaelknoch commented 6 years ago

hey @janekszynal I think its kind of weird to have a generic extension on CGSize that implements horizontal and vertical functions. What do you think about implementing something like a struct "Dimension" which has two props horizontal and portrait which actually return CGsize.

An example usage could be

var size: CGSize = Dimension.samsungGalaxyJ5.landscape
janek commented 6 years ago

That's a great idea, I was thinking in that direction, but couldn't pin the idea down exactly and just made this first version because I needed something. I'll happily change it to what you're suggesting.

So to make things clear:

thanks for the help @michaelknoch !