2

I know that similar questions have been addressed in the past, but I come back to this issue because I have a use case that I do not know how to handle.

The problem is this: I'm developing an app with many functions, which must always remain in portrait orientation: so far, nothing difficult. The problem comes with live streaming: through the use of native interfaces, I implemented a streaming solution that works well. In this case, since full screen streaming is the only case where the app has to be used in landscape, the trick is to keep the app locked in portrait: when the live streamer puts the mobile phone in landscape position, all the other users watching the streaming are forced to rotate the mobile phone in landscape to see the streaming correctly.

So far it would seem to be all solved, but it's not. What I didn't know, when I came up with this solution, is that during the streaming it must be possible to use a chat: this implies that the mobile phones must really be oriented in landscape.

A detail of the whole issue is that the native interfaces are used by me only for streaming recording, while for playback I use a Codename One MediaPlayer in non-native mode, so it can be customized and inserted in the Form as I want.

From all this, it follows that to put a chat over the live streaming I need to be able to change the screen orientation, unlocking it. I understand that on Android it's possible, while on iOS it's not.

I've never done something like this and I don't know how to handle this use case. It's not even clear to me where I find the space to make a chat in landscape orientation, it seems possible only in portrait orientation. Maybe the virtual keyboard could be made available only when the user holds the mobile phone in portrait and be hidden when the mobile phone is landscape oriented. The fact remains that everything else in the app must be locked in portrait.

I hope to receive useful suggestions. Thank you!

Francesco Galgani
  • 6,137
  • 3
  • 20
  • 23

2 Answers2

2

Locking orientation on iOS should work. Haven't tried it myself, but I see that the lockOrientation() method is implemented in the iOS port, and canForceOrientation() returns true in the IOSImplementation.

steve hannah
  • 4,586
  • 11
  • 18
  • Yes, the orientation lock works in iOS, what seems not to work is unlocking the orientation and then locking a different orientation, so that you have - in a portrait locked app - a landscape-oriented Form (or a completely unlocked Form, so that the user can turn the app as he prefers). – Francesco Galgani Aug 05 '20 at 16:14
  • 1
    I see. Something like this may work https://stackoverflow.com/a/50387102/2935174 If that is workable, then it should probably be utilized by the lockOrientation() method in CN1. – steve hannah Aug 05 '20 at 20:07
  • 1
    It works!!! Test case: https://github.com/codenameone/CodenameOne/issues/3209 – Francesco Galgani Aug 09 '20 at 23:22
1

It might be possible to force orientation lock changes, it requires recreating the view which is something that might seriously break things but it might work if you want to go deep into the native implementation code.

Another workaround used by some users is to avoid screen lock entirely and show a floating notification: "Please rotate the device to landscape". When the user is in the wrong orientation.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • What do you mean for "recreating the view"? Is it something that I can do in a native interface? I don't know what to do in this case. Could you add a code example? Thank you – Francesco Galgani Aug 05 '20 at 16:16