how to fetch data from firebase using expo react native app - firebase

Problem:
I am very new to react native and firebase stuff. I am making a train timetable system. There I have implemented a search function. This is how that component looks.
import React, { Component } from "react";
import {
StyleSheet,
Text,
TextInput,
View,
TouchableOpacity,
Dimensions,
Picker,
ListView
} from "react-native";
import {
Ionicons,
Foundation,
Entypo,
MaterialCommunityIcons,
FontAwesome,
MaterialIcons
} from "#expo/vector-icons";
import app from "../../config/db";
import { Autocomplete } from "react-native-autocomplete-input";
import { addItem } from '../../services/stationService';
const { height, width } = Dimensions.get("window");
const box_width = width / 2 + 40;
export default class TicketForm extends React.Component {
constructor(props) {
super(props);
this.state = {
start: "",
end: "",
class: "",
isLoading:false
};
}
static navigationOptions = {
title: "Tickets",
headerStyle: {
backgroundColor: "#2b78fe"
},
headerTintColor: "#fff",
headerTitleStyle: {
color: "#ffff"
}
};
search =()=>{
app.database().ref('/trains').on("value").then(snapshot=>{
console.log(snapshot);
})
}
render() {
var ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
return (
<View style={styles.form}>
<View style={styles.inputSection}>
<TextInput
style={styles.input}
placeholder="From"
onChangeText={start => {
this.setState({ start: start });
}}
underlineColorAndroid="transparent"
/>
<MaterialCommunityIcons
style={styles.inputicon}
name="backspace"
size={30}
color="#42a5f5"
/>
</View>
<View style={styles.inputSection}>
<TextInput
style={styles.input}
placeholder="To"
onChangeText={end => {
this.setState({ end: end });
}}
underlineColorAndroid="transparent"
/>
<MaterialCommunityIcons
style={styles.inputicon}
name="backspace"
size={30}
color="#42a5f5"
/>
</View>
<View style={styles.classSection}>
<Picker
selectedValue={this.state.class}
style={{ height: 50, width: box_width }}
onValueChange={(itemValue, itemIndex) =>
this.setState({ class: itemValue })
}
>
<Picker.Item label="1 st Class" value="1" />
<Picker.Item label="2 nd Class" value="2" />
<Picker.Item label="3 rd Class" value="3" />
</Picker>
</View>
<View style={styles.buttonCoontainer}>
<View style={styles.searchContainer}>
<TouchableOpacity onPress={this.search}>
<View style={styles.search}>
<Text style={styles.searchText}>Search</Text>
<Ionicons name="ios-search" size={30} color="#fff" />
</View>
</TouchableOpacity>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
form: {
flex: 1,
borderWidth: 3,
borderRadius: 8,
borderColor: "#ffff",
backgroundColor: "#ffff",
marginTop: 15,
marginLeft: 15,
marginRight: 15,
marginBottom: 5,
paddingTop: 50,
paddingLeft: 20,
paddingRight: 20
},
input: {
width: box_width,
flex: 1,
paddingTop: 5,
paddingRight: 5,
paddingBottom: 5,
paddingLeft: 0,
backgroundColor: "#fff",
color: "#424242"
},
inputSection: {
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
backgroundColor: "#fff",
borderColor: "#78909c",
borderWidth: 0.8,
paddingLeft: 5,
paddingRight: 5,
marginTop: 10,
marginBottom: 10
},
classSection: {
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
backgroundColor: "#e9ebee",
borderColor: "#e9ebee",
borderWidth: 0.8,
paddingLeft: 5,
paddingRight: 5,
marginTop: 10,
marginBottom: 10
},
dateSection: {
justifyContent: "center",
alignItems: "center",
backgroundColor: "#fff",
paddingLeft: 5,
paddingRight: 5,
marginTop: 10,
marginBottom: 10,
width: 335
},
inputIcon: {
padding: 10
},
reverseContainer: {
flexDirection: "row",
marginTop: 30
},
reverse: {
flexDirection: "row",
borderWidth: 0.5,
borderColor: "#eff0f1",
borderRadius: 5,
width: box_width / 2,
paddingTop: 3,
paddingBottom: 3,
paddingLeft: 20,
paddingRight: 10,
marginLeft: 0,
marginRight: 20,
backgroundColor: "#eff0f1"
},
reset: {
flexDirection: "row",
borderWidth: 0.5,
borderColor: "#eff0f1",
borderRadius: 5,
width: box_width / 2,
paddingTop: 3,
paddingBottom: 3,
paddingLeft: 20,
paddingRight: 10,
marginLeft: box_width / 4,
marginRight: 0,
backgroundColor: "#eff0f1"
},
reverseText: {
marginTop: 3,
marginRight: 10
},
resetText: {
marginTop: 3,
marginRight: 10
},
searchContainer: {
flexDirection: "row",
marginTop: 30
},
search: {
alignItems: "center",
flexDirection: "row",
borderWidth: 0.5,
borderColor: "#2089dc",
borderRadius: 5,
width: box_width + 80,
paddingTop: 6,
paddingBottom: 6,
paddingLeft: box_width / 2,
paddingRight: 10,
marginLeft: 0,
marginRight: 20,
backgroundColor: "#2089dc"
},
searchText: {
marginTop: 3,
marginRight: 10,
fontSize: 15,
fontWeight: "700",
color: "#ffff"
},
searchIcon: {
fontWeight: "700"
}
});
When I hit the search button there it is giving me an error. Here I am specifying how I implemented the action inside the search function.
app.database().ref('/trains').on("value").then(snapshot=>{
console.log(snapshot);
})
This is how I configure the firebase in my app and have imported it to my current component.
import Firebase from 'firebase';
let config = {
apiKey: "My Key",
authDomain: "my domain",
databaseURL: "https://mytrain-5beba.firebaseio.com",
projectId: "mytrain-5beba",
storageBucket: "mytrain-5beba.appspot.com",
messagingSenderId: "305193513552"
};
let app = Firebase.initializeApp(config);
// export const db = app.database();
export default app;
This is how my database looks like in the console.
Can someone help me to query this database correctly from my react native app?. Thank you very much.

You can try something like this:
.database()
.ref('/trains/')
.on('value', snapshot => {
const trains = snapshot.val();
console.warn(trains);
});

Related

Can't get this layout in react native:centering vertical text

this is a follow up question for my problem.
I have this layout and I want to use it as an component which will be more square shaped.
I am struggling trying to create this layout with css in react native.
Can someone help me? I really only need the style for centering the text on the left .
I appreciate your help.
type TeamsProps = {
name: string,
}
const TeamCard = (props: TeamsProps) => {
const [showOptions, setShowOptions] = useState<Boolean>(false)
const toggleOptions = () => {
setShowOptions(!showOptions)
}
return (
<View style={[styles.container, { height: (Dimensions.get("window").width - 3 * 15) / 2 }]}>
<TouchableOpacity onLongPress={toggleOptions} style={styles.card}>
<View style={styles.nameFlag}>
<Text style={styles.name}>{props.name}</Text>
</View>
<View style={styles.member}>
</View>
</TouchableOpacity>
{ showOptions ?
<TouchableOpacity onPress={toggleOptions} style={styles.options}>
<TextInput style={styles.input} value="Team Name"></TextInput>
<View style={styles.buttons}>
<TouchableOpacity style={[styles.button, styles.delete]}>
<Delete style={{ fontSize: 20, color: "white", margin: "auto" }} />
</TouchableOpacity>
<TouchableOpacity style={[styles.button, styles.confirm]}>
<Check style={{ fontSize: 20, color: "white", margin: "auto" }} />
</TouchableOpacity>
</View>
</TouchableOpacity>
: <></>
}
</View>
)
}
const styles = StyleSheet.create({
container: {
flexBasis: "calc(50% - 7.5px)"
},
card: {
backgroundColor: constants.mainColor,
borderRadius: 15,
shadowOpacity: 0.6,
shadowRadius: 10,
flex: 1,
flexDirection: "row",
alignItems: "center"
},
nameFlag: {
backgroundColor: constants.mainColorLight,
height: "calc(100% - 30px)",
width: "15%",
marginVertical: 15,
borderTopRightRadius: 30,
borderBottomRightRadius: 30,
justifyContent: "center"
},
name: {
position: "absolute",
// TODO: translateX needs to use -50%, translateY needs to use 50% of parent width
transform: [{ rotate: "-90deg" }, { translateX: -33 }, { translateY: 13 }],
transformOrigin: "left",
width: "max-content",
fontFamily: constants.fontFamilyHeader,
fontSize: constants.fontSizeHeader
},
member: {
backgroundColor: constants.mainColorLight,
height: "calc(100% - 30px)",
width: "calc(85% - 30px)",
margin: 15,
borderRadius: 30,
padding: 15,
flex: 1,
flexDirection: "row",
flexWrap: "wrap",
gap: 15,
justifyContent: "space-around",
alignItems: "center"
},
options: {
backgroundColor: constants.shadowColor,
position: "absolute",
top: 0,
left: 0,
zIndex: 100,
width: "100%",
height: "100%",
borderRadius: 15,
padding: 15,
flex: 1,
justifyContent: "center",
alignItems: "center",
gap: 25
},
input: {
backgroundColor: "white",
width: "100%",
borderRadius: 50,
padding: 5,
fontFamily: constants.fontFamilySubheader,
fontSize: constants.fontSizeHeader,
textAlign: "center"
},
buttons: {
flexDirection: "row",
gap: 25
},
button: {
borderRadius: 50,
width: 40,
height: 40
},
delete: {
backgroundColor: constants.alertColor
},
confirm: {
backgroundColor: constants.accentColor
}
})
weird shifting if text gets longer #Hammad Hassan
Try out this code and let me know
type CardProps= {
name: string
}
const Card = (props: CardProps) => {
return (
<View style={styles.container}>
<View style={styles.nameFlag}>
<Text style={styles.name}>{props.name}</Text>
</View>
<View style={styles.main}>
</View>
</View>
)
}
const styles = StyleSheet.create({
container: {
backgroundColor: constants.mainColor,
flex: 1,
flexDirection: "row"
},
nameFlag: {
backgroundColor: constants.mainColorLight,
height: "95%",
width: "15%",
marginVertical: "5%",
borderTopRightRadius: 50,
borderBottomRightRadius: 50,
justifyContent: "center"
},
name: {
transform: [{ rotate: "-90deg" }, { translateY: -12 }],
fontFamily: constants.fontFamily,
fontSize: constants.fonzSizeHeader,
textAlign: 'center',
marginRight: 'auto',
marginLeft: 'auto',
marginTop: 'auto',
marginBottom: 'auto'
},
main: {
backgroundColor: constants.mainColorLight,
height: "95%",
width: "75%",
margin: "5%",
borderRadius: 50
}
})
export { Card }

Center react native view

I'm creating a component to show the flag and country name. I'll like that view (image + text) centered in the available space.
So if the width of parent is all the screen, there will be space in the left and same in the right. If the parent is only 50% of the screen will be then left space on the sides...
What I've done:
<View style={styles.mainContainer} >
<View >
<TouchableOpacity
disabled={this.props.disablePicker}
onPress={() => this.setState({ modalVisible: true, dataSource: this.props.dataSource })}
activeOpacity={0.7}
>
<View>
<View style={[pickerStyle,{ flexDirection:'row'}]} >
<Image style={{}} source={selectedLabel.image} />
<Text style={}>{selectedLabel.name}</Text>
{dropDownImage ? <Image
style={dropDownImageStyle}
resizeMode="contain"
source={dropDownImage}
/> : null}
</View>
</View>
</TouchableOpacity>
</View>
</View>
const CountryPickerStyles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center"
},
itemSeparatorStyle:{
height: 1,
width: "90%",
alignSelf: "center",
backgroundColor: "#D3D3D3"
},
searchBarContainerStyle: {
marginBottom: 10,
flexDirection: "row",
height: 40,
shadowOpacity: 1.0,
shadowRadius: 5,
shadowOffset: {
width: 1,
height: 1
},
backgroundColor: "rgba(255,255,255,1)",
shadowColor: "#d3d3d3",
borderRadius: 10,
elevation: 3,
marginLeft: 10,
marginRight: 10
},
selectLabelTextStyle: {
color: "#000",
fontSize:16,
flexDirection: "row",
marginLeft: 100,
marginRight: 100
},
placeHolderTextStyle: {
color: "#757575",
padding: 10,
textAlign: "left",
width: "99%",
fontStyle: 'italic',
fontSize:12,
flexDirection: "row"
},
dropDownImageStyle: {
marginLeft: 10,
color: "#757575",
width: 10,
height: 10,
alignSelf: "center"
},
listTextViewStyle: {
color: "#000",
alignItems: "center",
justifyContent: "center",
marginLeft: 20,
marginHorizontal: 10,
textAlign: "left"
},
pickerStyle: {
elevation:0,
paddingRight: 10,
paddingLeft: 10,
marginRight: 10,
marginLeft: 10,
width:"90%",
borderWidth:0 ,
flexDirection: "row"
}
});
here's what I got:
https://pasteboard.co/JG5Rx9P.png
and also https://pasteboard.co/JG5Tthie.png

Expo Google places autocomplete - listView not clicable

I am trying to use the GooglePlacesAutocomplete, but once I make the address query, for example: "São C" and the "listView" return something like: "São Caetano, São Paulo ...", but when I try to select one option it seems like the list is not visible, because and the selection do not affect the item list.
this is the code I am using:
import * as React from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
import { colors, device, fonts } from '../constants';
// icons
import SvgTruck from './icons/Svg.Truck';
//const { onLocationSelected } = this.props
// constants
const GOOGLE_MAPS_APIKEY = '[API KEY]'
const WhereTo = () => (
<View style={styles.container}>
<View style={styles.containerBanner}>
<Text style={styles.bannerText}>15% off, up to $6.00</Text>
<Text style={styles.bannerMuted}>3 days</Text>
</View>
<View style={styles.containerInput} >
<View style={styles.containerSquare}>
<View style={styles.square} />
</View>
<GooglePlacesAutocomplete
styles={{
textInputContainer: {
flex: 1,
backgroundColor: 'transparent',
height: 54,
marginHorizontal: 20,
borderTopWidth: 0,
borderBottomWidth:0
},
textInput: {
height: 45,
left:0,
margin: 0,
borderRadius: 0,
paddingTop: 0,
paddingBottom: 0,
paddingLeft: 0,
paddingRight: 0,
padding: 0,
marginTop: 0,
marginLeft: 0,
marginRight: 0,
fontSize:18
},
listView: {
position:'absolute',
marginTop: 50
},
description: {
fontSize:16
},
row: {
padding: 18,
height:58
}
}}
placeholder="Para onde?"
onPress={(data, details) => {
// 'details' is provided when fetchDetails = true
console.log(data, details);
}}
query={{
key: GOOGLE_MAPS_APIKEY,
language: 'pt',
components: "country:br"
}}
textInputProps={{
autoCapitalize: "none",
autoCorrect: false
}}
fetchDetails
enablePoweredByContainer={false}
/>
<View style={styles.containerIcon}>
<SvgTruck />
</View>
</View>
</View>
);
const styles = StyleSheet.create({
container: {
top: Platform.select({ ios: 60, android: 40 }),
alignSelf: 'center',
position: 'absolute',
shadowColor: colors.black,
shadowOffset: { height: 2, width: 0 },
shadowOpacity: 0.2,
shadowRadius: 8,
top: device.iPhoneX ? 144 : 120,
width: device.width - 40
},
containerBanner: {
backgroundColor: colors.green,
borderTopLeftRadius: 4,
borderTopRightRadius: 4,
flexDirection: 'row',
justifyContent: 'space-between',
paddingHorizontal: 16,
paddingVertical: 8
},
bannerText: {
color: colors.white,
fontFamily: fonts.uberMedium,
fontSize: 12
},
bannerMuted: {
color: colors.mint,
fontFamily: fonts.uberMedium,
fontSize: 12
},
containerInput: {
alignItems: 'center',
backgroundColor: colors.white,
flexDirection: 'row',
height: 48
},
containerSquare: {
alignItems: 'center',
flex: 0.15
},
square: {
backgroundColor: colors.black,
height: 8,
width: 8
},
containerIcon: {
alignItems: 'center',
borderLeftColor: colors.greyMercury,
borderLeftWidth: 1,
flex: 0.2
}
});
export default WhereTo;
Can anyone trying to help me to solve it?
I recreated the Expo project and now it works, I could not found the root cause, but once that other project was made by other person and Expo make it easy to do and configure, it was fast enoght to create.
export default function AskForDriver () {
const [location, setLocation] = useState("");
const [errorMsg, setErrorMsg] = useState("");
useEffect(() => {
(async () => {
let { status } = await Location.requestPermissionsAsync();
if (status !== 'granted') {
setErrorMsg('Permission to access location was denied');
}
let location = await Location.getCurrentPositionAsync({});
setLocation(location);
})();
}, []);
let text = 'Waiting..';
if (errorMsg) {
text = errorMsg;
} else if (location) {
text = JSON.stringify(location);
console.log('location - latitude: ', location.coords.latitude)
console.log('location - longitude: ', location.coords.longitude)
}
return (
<View style={styles.container}>
<View style={styles.mainHeader}>
<Text style={styles.fontHeader}>Incluir flatlist com promoções e mensagens de incentivos</Text>
</View>
<View style={styles.searchHeader}>
<GooglePlacesAutocomplete
currentLocation
//styles={styles.placesautocomplete}
styles={{
textInputContainer: {
backgroundColor: 'grey',
},
placesautocomplete: {
flex:1,
},
textInput: {
height: 38,
color: '#5d5d5d',
fontSize: 16,
},
predefinedPlacesDescription: {
color: '#1faadb',
},
}}
placeholder='Search'
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data, details);
}}
query={{
key: 'YOUR API KEY',
language: 'pt',
components: 'country:br',
}}
/>
</View>
<MapView
style={styles.mapStyle}
showsMyLocationButton
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
>
</MapView>
{//<Text>{text}</Text>
}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
position: 'absolute',
alignContent:'center',
margin:0
},
mainHeader: {
backgroundColor: '#10002b',
padding:10,
},
fontHeader: {
color: '#e0aaff',
fontSize: 15,
},
searchHeader: {
borderColor: '#333',
borderWidth:5,
},
mapStyle: {
flex:1,
width: Dimensions.get('window').width,
height: Dimensions.get('window').height,
},
});

Attempt to invoke virtual method 'double java.lang.Double.doubleValue()' on a null object reference , react redux and when use connect

when i want to configuration react redux and set connect in my Routes
component i get this err ,
import React, { Component } from 'react';
import { connect } from 'react-redux'
import { Router, Scene, Actions } from 'react-native-router-flux';
import { Text, View, Image, TouchableOpacity, ImageBackground, AsyncStorage } from 'react-native';
import SendNumber from './src/container/SendNumber';
import EnterCode from './src/container/EnterCode';
import Home from './src/container/Home';
import Profile from './src/container/Profile';
import ResultItemsPage from './src/container/ResultItemsPage'
import Details from './src/container/Details'
//back button
const backButton = () => (
<TouchableOpacity
onPress={() => Actions.pop()}
style={{ width: 30, height: 20, marginLeft: 20 }}
>
<View style={{ alignItems: 'center' }}>
<Image
source={require('./Assets/Images/left-arrow.png')}
style={{ width: 30, height: 20 }}
/>
{/*
<Icon name='ios-arrow-round-back' style={{ color: '#fff' }} />
*/}
</View>
</TouchableOpacity>
);
const backButtonDetail = () => (
<TouchableOpacity
style={{
backgroundColor: '#33333320',
padding: 10,
width: 50,
height: 50,
borderRadius: 30,
justifyContent: 'center',
alignItems: 'center',
top: 10,
start: 10,
}} onPress={() => Actions.pop()} >
<Image style={{
width: 30,
resizeMode: 'contain'
}}
source={require('./Assets/Images/left-arrow-white.png')} />
</TouchableOpacity>
)
class Routes extends Component {
constructor(props) {
super(props)
this.state = {
login: false
}
}
_storeData = async () => {
try {
await AsyncStorage.setItem('login', 'true');
} catch (error) {
// Error saving data
}
};
_retrieveData = async () => {
try {
const value = await AsyncStorage.getItem('TASKS');
alert(value)
} catch (error) {
// Error retrieving data
}
};
componentWillMount() {
this._storeData();
this._retrieveData();
}
render() {
return (
<Router>
<Scene key="root" >
<Scene key="SendNumber"
component={SendNumber}
title="Send Number"
hideNavBar={true}
initial={true}
/>
<Scene key="EnterCode" component={EnterCode}
title=""
titleStyle={{ color: 'transparent' }}
renderBackButton={() => backButton()}
navigationBarStyle={styles.login_style_bar}
sceneStyle={styles.login_scene_style}
/>
<Scene key="Home"
component={Home}
title="home"
hideNavBar={true}
/>
<Scene key="Profile" component={Profile}
title=""
titleStyle={{ color: 'transparent' }}
renderBackButton={() => backButton()}
navigationBarStyle={styles.login_style_bar}
sceneStyle={styles.login_scene_style}
/>
<Scene key="ResultItemsPage" component={ResultItemsPage}
title=""
titleStyle={{ color: 'transparent' }}
renderBackButton={() => backButton()}
navigationBarStyle={styles.login_style_bar}
sceneStyle={styles.login_scene_style}
onRight={() => alert('right')}
// rightButtonImage={require('./Assets/Images/bell.png')}
renderRightButton={() => (
<TouchableOpacity style={styles.notification_box}
onPress={() => alert('توجهات')}>
<ImageBackground
style={styles.bell}
source={require('./Assets/Images/bell.png')}
>
<View style={styles.notification} >
<Text style={styles.notification_text} >3</Text>
</View>
</ImageBackground>
</TouchableOpacity>
)}
/>
<Scene key="Details" component={Details}
title=""
titleStyle={{ color: 'red' }}
renderBackButton={() => backButtonDetail()}
navigationBarStyle={styles.login_style_bar_detail}
sceneStyle={styles.login_scene_style}
/>
</Scene>
</Router >
)
}
}
const mapStateToProps = state => {
return {
status: state.number.loginStatus
}
}
export default connect(mapStateToProps)(Routes);
const styles = ({
login_style_bar: {
backgroundColor: '#f6f6f6',
shadowColor: "#f7f7f7",
elevation: 0,
height: 50,
},
login_style_bar_detail: {
backgroundColor: 'transparent',
shadowColor: "#f7f7f7",
elevation: 0,
height: 50,
},
bell: {
width: 30,
height: 30,
justifyContent: 'center',
alignItems: 'center',
},
notification: {
width: 14,
height: 14,
borderRadius: 7,
backgroundColor: '#B22850',
start: 10,
top: -10,
justifyContent: 'center',
alignItems: 'center',
},
notification_text: {
color: '#fff',
fontSize: 9,
fontFamily: 'ISFMedium',
},
notification_box: {
width: 40,
height: 40,
right: 20,
justifyContent: 'center',
alignItems: 'center',
},
bell: {
width: 30,
height: 30,
justifyContent: 'center',
alignItems: 'center',
},
notification: {
width: 14,
height: 14,
borderRadius: 7,
backgroundColor: '#B22850',
start: 10,
top: -10,
justifyContent: 'center',
alignItems: 'center',
},
notification_text: {
color: '#fff',
fontSize: 9,
fontFamily: 'ISFMedium',
},
})

iFrame Border Showing in WebView React Native

In attempts to dynamically add youtube videos to my React Native app, I chose to use a combination of WebView and iFrame since the current react-native-youtube component doesn't work for RN 16^. Ultimately, the solution does work, but the iframe border still shows and will not go away (even with css or frameborder = 0), nor can I change it's color with css. Any ideas? Here's my code:
video-preview component (where users can see video, title, etc before tapping):
module.exports = React.createClass({
render: function() {
return (
<TouchableHighlight
style={styles.touchCard}
underlayColor={'transparent'}
onPress={this.props.onPress} >
<View style={styles.card}>
<WebView
style={styles.videoPreview}
automaticallyAdjustContentInsets={true}
scrollEnabled={false}
style={styles.videoPreview}
html={this.props.source}
renderLoading={this.renderLoading}
renderError={this.renderError}
automaticallyAdjustContentInsets={false} />
<View style={[styles.container, this.border('organge')]}>
<View style={[styles.header, this.border('blue')]}>
<Text style={[styles.previewText]}>{this.props.text}</Text>
</View>
<View style={[styles.footer, this.border('white')]}>
<View style={styles.sourceRow}>
<View style={[this.border('white')]}>
<ImageButton
style={[styles.logoBtn, , this.border('red'), styles.row]}
resizeMode={'contain'}
onPress={this.onHeartPress}
source={this.props.src} />
</View>
<View style={[this.border('white')]}>
<Text style={[styles.rowText, {fontWeight: 'bold'}]}>{this.props.entryBrand}</Text>
<Text style={[styles.rowText]}>{this.props.views}</Text>
</View>
</View>
<View style={[styles.heartRow, this.border('black')]}>
<KeywordBox
style={[styles.category, this.border('blue')]}
key={this.props.key}
text={this.props.category}
onPress={this.props.categoryPress}
selected={this.props.selected} />
</View>
</View>
</View>
</View>
</TouchableHighlight>
);
Which looks like this:
And the input iframe html into the webview looks like this:
<iframe style='border: 0;border-width: 0px;' scrolling='no' frameborder='0' width='320' height='300' src='https://www.youtube.com/embed/2B_QP9JGD7Q'></iframe>
Here's my styling:
var styles = StyleSheet.create({
centerText: {
marginBottom:5,
textAlign: 'center',
},
noResultsText: {
marginTop: 70,
marginBottom:0,
color: '#000000',
},
sourceRow: {
justifyContent: 'space-around',
flexDirection: 'row',
},
rowText: {
textAlign: 'left',
color: 'white',
fontSize: 12,
marginLeft: 5,
fontFamily: 'SFCompactText-Medium'
},
detailText: {
fontFamily: 'SFCompactText-Light',
fontSize: 18,
color: 'white',
textAlign: 'left',
marginTop: 2,
marginLeft: 5,
},
touchCard: {
margin: 3,
width: window.width*0.95,
shadowOffset: {width: 2, height: 2},
shadowOpacity: 0.5,
shadowRadius: 3,
alignSelf:'center',
},
card: {
flex: 1,
width: window.width*0.98,
alignSelf:'center',
},
heartText: {
color: 'white',
fontSize: 12,
fontWeight: 'bold',
alignSelf: 'center',
fontFamily: 'SFCompactText-Medium'
},
heartRow: {
flexDirection: 'row',
justifyContent: 'space-around',
alignSelf: 'center',
justifyContent: 'center',
},
logoBtn: {
height: window.width/10,
width: window.width/10,
alignSelf:'center',
},
heartBtn: {
height: (92/97)*(window.width/13),
width: window.width/13,
alignSelf:'center',
},
category: {
fontFamily: 'Bebas Neue',
fontSize: 10,
fontWeight: 'bold'
},
header: {
flex: 1,
justifyContent: 'space-around',
marginTop: window.height/60,
},
footer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
margin: window.height/80,
},
container: {
flex: 1,
backgroundColor: '#1a1a1a',
},
videoPreview: {
flex: 2,
height: window.width*0.85,
width:window.width*0.98,
flexDirection: 'column'
},
previewText: {
fontFamily: 'Bebas Neue',
fontSize: 23,
color: 'white',
textAlign: 'left',
marginTop: 2,
marginLeft: 5,
},
});

Resources