I am creating a simple video app using the react native for IOS. But the problem is that when i play the video the video is played in the full screen mode, even if I set the property allowsInlineMediaPlayback to true but still no impression. Please can anyone tell why we use the allowsInlineMediaPlayback property and how to enable the inline video mode in IOS?
Even i added the webkit-playsinline attribute to the HTML video tag as well but which is documented (as following) on the react native website but still not working.
NOTE:
In order for video to play inline, not only does this property need to
be set to true, but the video element in the HTML document must also
include the webkit-playsinline attribute.
Please take a look at the following links:
Documentation Reference For WebView.allowsInlineMediaPlayback.
Working Source Code.
Thanks !!!
Simply remove webkit prefix from webkit-playsinline because webkit prefix is no longer required nor it is supported.
Following is the correct and modified code snippet of your code you shared in the question:
import React, { Component } from 'react';
import { WebView, View } from 'react-native';
export default class MyVideoApp extends React.Component{
render(){
return(
<View style={{
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'
}}>
<WebView
source={{
html: '<video playsinline controls autoplay src="https://www.w3schools.com/html/mov_bbb.mp4" ></video>'
}}
useWebKit={true}
originWhitelist={['*']}
allowsInlineMediaPlayback={true}
style={{
height: 600,
width: 400,
}}/>
</View>
);
}
}
enter "playsInline" in your video tag
Related
I'm working on a small react-native app. It's nearly only a container for showing my webapp, so nearly everthing is running cool.
The problem is, the user needs to rotate the screen on some of the webapp-sites. With my implementation this works very good on android, but not on iOS. The funny thing is, when I start the app on iOS via EXPO GO, it also works.
I've searched a lot but I can not find a solution for this. Do you have any idea how to change that behavior on iOS?
This is my App.js
import React from "react";
import { StyleSheet, View } from "react-native";
import WebView from 'react-native-webview';
const WEBSITE = 'https://www.google.com'
export default function App() {
return (
<View style={styles.container}>
<View style={{ width: '100%', height: '100%' }}>
<WebView
source={{ uri: WEBSITE }}
/>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "flex-start",
alignItems: "flex-start",
},
});
I would first check your xcode project settings and ensure that the orientations you are looking for are enabled. If you open up xcode and check the orientations you should have all the orientations selected that you want to support. The project below has only portrait enabled therefore I'd suggest you enable the landscape orientations and hopefully this should resolve your problem.
I am rendering a html page from a CMS(content management system) in react-native-webview. The html has a video and for mobile they are hiding it using display:none, it works on android. But in iOS the video is opening in full screen even if the enclosing div component has display:none.
I want to hide this video in web-view. After a research I have used allowsInlineMediaPlayback={true} in web view and playsInline in video tag it is worked.
Questions
For me the content is coming from CMS and authored by another team. I dont have any control over there to add playsInline in video tags. How do I achieve hiding video?
Why the enclosing div display:none is not working? is there a way to not to display using html properties in that div level?
import { SafeAreaView } from "react-native";
import { WebView } from 'react-native-webview';
export default class App extends React.Component {
render() {
return (
<SafeAreaView style={{ flex: 1 }}>
<WebView
source={{
html: '<div style="display:none;"><video autoplay src="https://www.w3schools.com/html/mov_bbb.mp4" ></video></div>'
}}
originWhitelist={['*']}
allowsInlineMediaPlayback={true}
/>
</SafeAreaView>
);
}
}```
I'm doing a multiplatform app in react-native, but some layout properties are working in Android but not in IOS. After some search in our code, we figure out that the inline properties are the thing giving us throuble, like in that code:
<Button
style={principal_style.botoes}
backgroundColor='#e3e3e3'
onPress={() => this.logaUser() }>
<Text style={principal_style.btntxtstylewhite}>{this.state.txtEntrar}</Text>
</Button>
The backgroundColor propertie is completely ignored, and that problem repeats in every CSS propertie used that way, width, height, everhthing. Even if I put the properties inside the Style prop, it doesn't do anything, like in that code:
<View style={{flex: 1, justifyContent: 'center', }}>
<Text style={{color:'#ffffff', fontSize:12, textAlign: 'center', marginTop: 20,}}>V - 0.02</Text>
</View>
Now, about the external Stylesheet, they work perfectly, like the first code fragment, it has a style prop called principal_style.botoes, here is the code:
botoes: {
flex: 2,
backgroundColor: 'blue',
height:70,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
marginLeft: 40,
marginRight: 40,
borderRadius: 20,
marginBottom: 20
},
I don't know what else to do, maybe some react command, anything to work with, the inline style should work in IOS, right?
Please, give me some light about that.
EDIT 1
I could solve the first problem with that
<TouchableHighlight style={[styles.button,{ backgroundColor: '#f00'}]}
CREDITS: Answer from another thread
EDIT 2 - SOLUTION
I managed to solve the problems, turns out that the whole thing was caused by I mistake, the flex propertie was wrong, i had mixed it with other ways of height, and that made the whole text disappear, now everything is work perfectly, the advice that I can give to anyone ho gets that kind of problem is that everything works if you do the right way.
proper way to overwrite a external style to work in both platforms
<TouchableHighlight style={[styles.button,{ backgroundColor: '#f00'}]}
I forgot to mention that I was using the NATIVE-BASE button
I am currently working on my very first react-native application and am wondering how that slide in effect of a new view can be achieved and where that "hidden" view should be placed.
My Application is currently build like this:
<View style={{flex:1}}>
<View style={{flex:.8, justifyContent:'center'}}>
.. some login Form
</View>
<View style={{flex:.2, justifyContent:'center', alignItems:'center'}}>
<TouchableHighlight onPress={this._toggleRegistryView}>
<Text> or register here </Text>
</TouchableHighlight>
</View>
</View>
As you can see in this basic code I want to slide-in the Registration View as soon as the touchable component is pressed.
Do I need to store the view "invisible" with a width of 0 and height of 100% on one side and then animate it to the full device width?
Right now I have no idea besides a whole new view render when the state changes
render(){
return({this.state.view == 'login' ? <LoginView /> : <RegistryView />});
}
Unfortunately this triggers a "hard" view change and not a smooth right to left or left to right animation where the view slides in.
If my question was unclear please inform me - I'll gladly try to specify it :) Thank you for your help
You should split your application into multiple scenes (screens) and use the Navigator component to transition between the scenes.
Here is a tutorial from the TaskRabbit blog to get you started.
Once you have you scenes set up, you can experiment with different SceneConfigs for different types of transition animations.
A transition from a page to another is nothing else but navigation.
In order to navigate from a page to another in React Native, you will want a navigation library.
The default Navigator component from React Native might work, but it's got a lot of limitations and issues, and the default solution most people turn to (and which after 3yrs of RN I strongly recommend), is React Navigation. If you are using Expo, it also ships by default, so you can jump right into it, and define your screens like so:
import React from 'react';
import { View, Text } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
</View>
);
}
}
const AppNavigator = createStackNavigator({
Login: {
screen: LoginView,
},
Register: {
screen: RegisterView,
},
});
export default createAppContainer(AppNavigator);
If not, here's a quick start guid to using it outside of Expo.
My TextInput is missing inside ScrollView for iOS. It works fine on android.
Included is the sample app using Playground.
https://rnplay.org/apps/KtTZ2g
You could see that android is showing the TextInput, but the iOS's one does not show it.
These kind of bugs is making me crazy...
When using the TextInput, be sure to provide a height:
<TextInput
style={{flex: 1, color: 'black', height:40}}
editable={false}
defaultValue="+"
underlineColorAndroid='#C8C7CC' />
https://rnplay.org/apps/a6i08w