Hi @anhtuank7c,
"How to lock screen orientation in ViroVideo"
I'm not clear as to what you are trying to achieve here - can you explain the use case customer experience that you have in mind in this scenario? For example, are you trying to lock the screen orientation when a user views a 3D scene with a ViroVideo?
It is also important to note that developers should not be manipulating screen orientation modes in VR - it should always be landscape, as the customer is viewing the experience through the VR HMD (modifying it would cause unexpected visual experiences).
Also, as existing options are already available - device orientations are handled by the native mobile APIs already, and possibly by existing react native libraries / addons - we do not see the need yet to add additional support for locking screen orientation through the Viro APIs.
"I want handle toggle vrModeEnabled in ViroSceneNavigator."
You can do this by creating ReactNative boolean state that toggles the vrModeEnabled value within the ViroSceneNavigator. For example, within the App.js in Viro's Hello world example:
// Add a vrModeEnabledFlag to as a boolean state (around line 50)
this.state = {
navigatorType : defaultNavigatorType,
sharedProps : sharedProps,
vrModeEnabledFlag: true // Add flag here
}
// Associate this flag with the vrModeEnabled property in the ViroSceneNavigator (around line 111)
<ViroSceneNavigator vrModeEnabled={this.state.vrMode}/>
// Create a function to call to change the state
_setVrModeEnabled(enabled) {
this.setState({
vrModeEnabledFlag : enabled
});
}
However, please note that there is also currently a bug with switching between 360 mode and vr mode that we are currently looking at at the moment as well.
Good day @dthian
I am sorry about unclear question.
I can redescribed the question.
I used vrModeEnabled={false} to display ViroV360Video in 2D mode.
example code:
<ViroSceneNavigator
debug={false}
vrModeEnabled={false}
apiKey={configs.vrKey}
initialScene={{
scene: () => (
<ViroScene onClick={() => this.onToggleActionBar()}>
<Viro360Video
loop={false}
source={require('~/assets/videos/360.mp4')}
/>
</ViroScene>
)
}}
onExitViro={onDone}
/>
The problem only on Android, i do lock screen orientation to portrait only in AndroidManifest.xml, and choose also lock screen in phone settings to portrait
android:screenOrientation="portrait"
I am not switching between mono to vr mode, keep using mono mode only.
Quotations:
"It is also important to note that developers should not be manipulating screen orientation modes in VR - it should always be landscape, as the customer is viewing the experience through the VR HMD (modifying it would cause unexpected visual experiences)."
=> You are right, but for now i have to work with my customer, sometime they just want me to follow the design :D
Thank you so much.
Hey @anhtuank7c, thanks for your further explaining your situation, that helped alot!
With regards to Case 2 as you mentioned above, that sounds like a bug on the Viro Platform. The app should not rotate back to landscape if you've specifically set the orientation to portrait.
I'll file a bug on the backlog so that we can take a look at it. As a mitigation / workaround, you can enforce your portrait mode by adding this following line of code to your MainActivity.java:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Do let us know if that still does not work. Thanks!
WOW, you saved my day. Thank you so much.
It's rotate landscape then back to portrait in the first time.
The second time not rotate landscape again.
So i think this is an issue and still need fix
Hi @anhtuank7c, I'm not sure if i understand - from the above, weren't you trying to lock the application in portrait mode (when attempting to set android:screenOrientation="portrait")? I've tested the onConfiguration patch again and the portrait orientation is retained if you enter the app the first time, and even if you exit and re-enter the application - as such it should work. If not, can you send the repro case steps you've done to get into a situation where it doesn't work?
For the moment, the onConfiguration patch is just a mitigation - this is still indeed a bug on our platform that will need to be fixed, so let's keep this issue open until then.
"The second time not rotate landscape again."
Closing this issue due to inactivity. Please reopen if you can provide additional clarification/info and we would be happy to help.
Hello
It still happens with react-viro: 2.14.0 :)
Anyone can check?
Thanks!
Hey @tuananhcwrs, that is strange. But does the above mitigation not work for you?
Hello @dthian ,
Bad luck that nothing working :(
Thanks!
@tuananhcwrs did you try the mitigation above? Did you see the issue persist even with the mitigated solution above?
Hello,
I use this
You suggestion was:
I'll file a bug on the backlog so that we can take a look at it. As a mitigation / workaround, you can enforce your portrait mode by adding this following line of code to your MainActivity.java:
```@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
```
Do let us know if that still does not work. Thanks!
But it does not work. Video keeps flicking
Most helpful comment
Hey @anhtuank7c, thanks for your further explaining your situation, that helped alot!
With regards to Case 2 as you mentioned above, that sounds like a bug on the Viro Platform. The app should not rotate back to landscape if you've specifically set the orientation to portrait.
I'll file a bug on the backlog so that we can take a look at it. As a mitigation / workaround, you can enforce your portrait mode by adding this following line of code to your MainActivity.java:
Do let us know if that still does not work. Thanks!