import React, { Component } from "react";
import {
Platform,
StyleSheet,
Text,
View,
TouchableOpacity,
Alert,
Image,
Button,
TextInput,
Dimensions
} from "react-native";
import { Dialog } from "react-native-simple-dialogs";
import AsyncStorage from "#react-native-community/async-storage";
import { KeyboardAvoidingView } from "react-native";
import DropdownAlert from "react-native-dropdownalert";
import { BoxShadow } from "react-native-shadow";
import { DrawerActions } from "react-navigation-drawer";
import MapView, { PROVIDER_GOOGLE } from "react-native-maps";
import datum from "./data";
import { Marker } from "react-native-maps";
import Parse from "parse/react-native";
import Geolocation from "react-native-geolocation-service";
import { GooglePlacesAutocomplete } from "react-native-google-places-autocomplete";
const homePlace = {
description: "Home",
geometry: {
location: {
lat: 48.8152937,
lng: 2.4597668
}
}
};
const workPlace = {
description: "Work",
geometry: {
location: {
lat: 48.8496818,
lng: 2.2940881
}
}
};
export default class Home extends React.Component {
constructor(props) {
super(props);
this.state = {
lat: 12.9122536,
long: 80.0987121,
picklat: 12.9122536,
picklong: 80.0987121,
droplat: 12.9202954,
droplong: 80.1026819,
curautostate: "pick",
curautostateplaceholder: "Enter your pick up location",
distance: 0,
windowwidth: Dimensions.get("window").width,
windowheight: Dimensions.get("window").height
};
}
componentDidMount() {
Geolocation.requestAuthorization();
Geolocation.getCurrentPosition(
position => {
this.setState({
lat: position.coords.latitude
});
this.setState({
long: position.coords.longitude
});
this.setState({
picklat: position.coords.latitude
});
this.setState({
picklong: position.coords.longitude
});
this.setState({
droplat: position.coords.latitude
});
this.setState({
droplong: position.coords.longitude
});
},
error => {
Alert.alert(
"Please enable the location service",
error.message,
[
{
text: "OK",
onPress: () => console.log("has to exit")
}
],
{
cancelable: false
}
);
},
{
enableHighAccuracy: true,
timeout: 15000,
maximumAge: 10000
}
);
}
tooglestate = getstate => {
if (getstate == "drop") {
this.setState({
curautostate: "drop"
});
this.setState({
curautostateplaceholder: "Enter your drop location"
});
this.setState({
lat: this.state.droplat,
long: this.state.droplong
});
} else if (getstate == "pick") {
this.setState({
curautostate: "pick"
});
this.setState({
curautostateplaceholder: "Enter your pick location"
});
this.setState({
lat: this.state.picklat,
long: this.state.picklong
});
} else {
}
};
executeautocompleteView = text => {
console.log(text);
};
render() {
return (
<View
style={{
flex: 1,
flexDirection: "column",
backgroundColor: datum.secondaryColor
}}
>
<View
style={{
backgroundColor: "#E8EDF1",
width: "100%",
height: "9%",
top: 0,
zIndex: 1,
shadowColor: datum.secondaryColor,
elevation: 20,
flexDirection: "column"
}}
>
<Image
source={require("./Drawbles/Homeicon.png")}
resizeMode="contain"
style={{
width: "10%",
height: "100%",
alignSelf: "center"
}}
/>
</View>
<MapView
style={styles.map}
initialRegion={{
latitude: this.state.lat,
longitude: this.state.long,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}
region={{
latitude: this.state.lat,
longitude: this.state.long,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}
>
<Marker
draggable
coordinate={{
latitude: this.state.picklat,
longitude: this.state.picklong
}}
pinColor={"#56954A"}
onDragEnd={e => {
this.setState({
picklat: e.nativeEvent.coordinate.latitude,
picklong: e.nativeEvent.coordinate.longitude,
lat: e.nativeEvent.coordinate.latitude,
long: e.nativeEvent.coordinate.longitude
});
}}
/>
<Marker
draggable
coordinate={{
latitude: this.state.droplat,
longitude: this.state.droplong
}}
pinColor={"#C5441B"}
onDragEnd={e =>
this.setState({
droplat: e.nativeEvent.coordinate.latitude,
droplong: e.nativeEvent.coordinate.longitude,
lat: e.nativeEvent.coordinate.latitude,
long: e.nativeEvent.coordinate.longitude
})
}
/>
</MapView>
<View
style={{
flexDirection: "row",
backgroundColor: datum.secondaryColor,
zIndex: 1,
alignSelf: "center",
top: "10%",
height: this.state.windowheight * 0.07,
width: this.state.windowwidth * 0.9,
shadowColor: datum.secondaryColor,
elevation: 20
}}
>
<TouchableOpacity onPress={() => this.tooglestate("pick")}>
<View
style={{
width: this.state.windowwidth * 0.13,
height: this.state.windowheight * 0.07,
backgroundColor: "#56954A"
}}
/>{" "}
</TouchableOpacity>
<GooglePlacesAutocomplete
placeholder="Search"
minLength={2} // minimum length of text to search
autoFocus={false}
returnKeyType={"search"} // Can be left out for default return key https://facebook.github.io/react-native/docs/textinput.html#returnkeytype
keyboardAppearance={"light"} // Can be left out for default keyboardAppearance https://facebook.github.io/react-native/docs/textinput.html#keyboardappearance
listViewDisplayed="auto" // true/false/undefined
fetchDetails={true}
renderDescription={row => row.description} // custom description render
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data, details);
}}
getDefaultValue={() => ""}
query={{
// available options: https://developers.google.com/places/web-service/autocomplete
key: "6Iza4Sy3APa34ewekfaM3yZB-Tt6SNO4",
language: "en", // language of the results
types: "(cities)" // default: 'geocode'
}}
styles={{
textInputContainer: {
width: "100%",
backgroundColor: datum.primaryColor
},
description: {
fontWeight: "bold"
},
textInput: {
backgroundColor: datum.primaryColor
},
predefinedPlacesDescription: {
color: datum.primaryColor
}
}}
currentLocationLabel="Current location"
nearbyPlacesAPI="GooglePlacesSearch" // Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
GoogleReverseGeocodingQuery={
{
// available options for GoogleReverseGeocoding API : https://developers.google.com/maps/documentation/geocoding/intro
}
}
GooglePlacesSearchQuery={{
// available options for GooglePlacesSearch API : https://developers.google.com/places/web-service/search
rankby: "distance",
type: "cafe"
}}
GooglePlacesDetailsQuery={{
// available options for GooglePlacesDetails API : https://developers.google.com/places/web-service/details
fields: "formatted_address"
}}
filterReverseGeocodingByTypes={[
"locality",
"administrative_area_level_3"
]} // filter the reverse geocoding results by types - ['locality', 'administrative_area_level_3'] if you want to display only cities
debounce={200} // debounce the requests in ms. Set to 0 to remove debounce. By default 0ms.
/>
<TouchableOpacity onPress={() => this.tooglestate("drop")}>
<View
style={{
width: this.state.windowwidth * 0.13,
height: this.state.windowheight * 0.07,
backgroundColor: "#C5441B"
}}
/>{" "}
</TouchableOpacity>
</View>
<View
style={{
backgroundColor: datum.secondaryColor,
width: "100%",
height: "9%",
top: "90%",
zIndex: 2,
shadowColor: datum.secondaryColor,
elevation: 20,
flexDirection: "row"
}}
/>
<DropdownAlert ref={ref => (this.dropdown = ref)} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF"
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10
},
instructions: {
textAlign: "center",
color: "#333333",
marginBottom: 5
},
map: {
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 2
},
headertext: {
fontSize: 20,
textAlign: "center",
color: datum.secondaryColor,
margin: 10
},
bookingbar: {
flex: 1,
flexDirection: "row",
height: "30%",
width: "100%",
zIndex: 30,
bottom: 0
}
});
I am trying to align the Last view comp to top '90%' but somehow my layout breaks I don't know what went wrong, my black view is supposed to be at the bottom edge of the comp but it slight align up where it suppose to be, I have tried using point/and percentages but nothing seems to work, I don't where is the mistake is that with me or with react native library
You are missing the absolute position property, try this:
<View style={{
backgroundColor: 'blue',
position: 'absolute',
width: '100%',
height: '10%',
top: '90%',
zIndex: 2,
shadowColor: 'black',
elevation: 20,
flexDirection: 'row'
}}/>
Related
I want to rotate the MapView as per the phone rotation. I am not getting a solution in official documentation, so I did a trick to do it by rotating the layout by setting the transform style but I can understand it is not the perfect solution because the labels over the screen also rotating with the layout.
If it is possible by animateCamera, Please suggest me how can I update the code.
I have attached a screenshot of the issue and relevant code block.
import MapView from 'react-native-maps';
import { Bubbles, DoubleBounce } from 'react-native-loader';
class TestPropUpdate extends Component {
constructor(props) {
super(props);
this.state = {
origin: null,
latlong: null,
initialRegion: null,
compasAngle: 0
};
}
componentDidUpdate() {
CompassHeading.start(3, ({ heading, accuracy }) => {
if (this.state.compasAngle !== heading) {
this.setState({ compasAngle: heading })
console.log(heading)
}
CompassHeading.stop();
})
}
getCurrentLocation = () => ({
latitude: this.state.latlong.currentLatitude,
longitude: this.state.latlong.currentLongitude,
latitudeDelta: 0.01,//0.01155,
longitudeDelta: 0.01//0.01155
});
setCurrentLocation = (locationChangedResult) => {
this.setState({
latlong: {
"currentLatitude": locationChangedResult.nativeEvent.coordinate.latitude,
"currentLongitude": locationChangedResult.nativeEvent.coordinate.longitude
}
})
}
render() {
return (
<SafeAreaView style={{ flex: 1, position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center' }}>
{this.state.latlong ?
<MapView
onUserLocationChange={locationChangedResult => this.setCurrentLocation(locationChangedResult)}
region={this.getCurrentLocation()}
style={[
styles.mapStyle,
{
transform: [{ rotate: `${360 - this.state.compasAngle}deg` }],
}
]}
>
</MapView>
: <DoubleBounce />}
</SafeAreaView>
);
}
}
export default TestPropUpdate;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
padding: 10,
alignItems: 'center',
justifyContent: 'center',
},
boldText: {
fontSize: 25,
color: 'red',
marginVertical: 16,
textAlign: 'center'
},
mapStyle: {
position: 'absolute',
width: "200%",
height: "100%",
}
});
when I upload a video from my gallery and then try to navigate to the next screen,the video keeps playing in the background.
below is my code:
import React, {PureComponent} from 'react';
import {
StyleSheet,
Text,
TouchableOpacity,
View,
Animated,
ProgressBarAndroid,
} from 'react-native';
import {RNCamera} from 'react-native-camera';
import Icon from 'react-native-vector-icons/Entypo';
import ImagePicker from 'react-native-image-crop-picker';
import Video from 'react-native-video';
import { withNavigationFocus } from 'react-navigation';
class Shoot extends PureComponent {
constructor(props) {
super(props);
this.state = {
recording: false,
processing: true,
upload: false,
galleryVideo: '',
progress30: '',
progress60: '',
progress15: 0,
video: '',
progressStatus: 0,
progressStatus60: 0,
progressStatus15: 0,
videoPaused: false
};
}
render() {
return (
<View style={styles.container}>
{this.state.upload == true && (
<TouchableOpacity
style={{
backgroundColor: '#e75480',
position: 'absolute',
width: 80,
height: 30,
zIndex: 2,
padding: 5,
borderRadius: 5,
right: 0,
justifyContent: 'center',
alignContent: 'center',
}}
onPress={() => this.props.navigation.navigate('Post', {key: 1})}>
<Text style={{color: 'white', textAlign: 'center'}}>Next</Text>
</TouchableOpacity>
)}
{this.state.upload == false && (
<TouchableOpacity
style={{
position: 'absolute',
bottom: 0,
right: '15%',
justifyContent: 'center',
alignItems: 'center',
}}
onPress={this.video.bind(this)}>
<Icon name="image" size={30} color="white" />
<Text style={{color: 'white', fontWeight: 'bold'}}>Upload</Text>
</TouchableOpacity>
)}
<TouchableOpacity
onPress={this.take60sVideo.bind(this)}
style={{
width: 60,
height: 60,
justifyContent: 'center',
alignContent: 'center',
position: 'absolute',
bottom: 0,
left: '25%',
}}>
<Text style={{textAlign: 'center', color: 'red', fontSize: 15}}>
60s
</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={this.take15sVideo.bind(this)}
style={{
width: 60,
height: 60,
justifyContent: 'center',
alignContent: 'center',
position: 'absolute',
bottom: 0,
left: '5%',
}}>
<Text style={{textAlign: 'center', color: 'red', fontSize: 15}}>
15s
</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={this.take30sVideo.bind(this)}
style={styles.capture}></TouchableOpacity>
{this.state.progress30 === true && (
<View
style={{
width: '100%',
height: 15,
top: 0,
position: 'absolute',
bottom: 0,
zIndex: 2,
}}>
{/* <Animated.View
style={
([StyleSheet.absoluteFill],
{backgroundColor: '#8BED4F', width: '50%', height: 10})
}
/> */}
<ProgressBarAndroid
styleAttr="Horizontal"
progress={this.state.progressStatus}
indeterminate={false}
color="#e75480"
/>
</View>
)}
{this.state.progress60 === true && (
<View
style={{
width: '100%',
height: 15,
top: 0,
position: 'absolute',
bottom: 0,
zIndex: 2,
}}>
{/* <Animated.View
style={
([StyleSheet.absoluteFill],
{backgroundColor: '#8BED4F', width: '50%', height: 10})
}
/> */}
<ProgressBarAndroid
styleAttr="Horizontal"
progress={this.state.progressStatus60}
indeterminate={false}
color="#e75480"
/>
</View>
)}
{this.state.progress15 === true && (
<View
style={{
width: '100%',
height: 15,
top: 0,
position: 'absolute',
bottom: 0,
zIndex: 2,
}}>
{/* <Animated.View
style={
([StyleSheet.absoluteFill],
{backgroundColor: '#8BED4F', width: '50%', height: 10})
}
/> */}
<ProgressBarAndroid
styleAttr="Horizontal"
progress={this.state.progressStatus15}
indeterminate={false}
color="#e75480"
/>
</View>
)}
{this.state.video == '' ? (
<RNCamera
ref={(ref) => {
this.camera = ref;
}}
style={styles.preview}
type={RNCamera.Constants.Type.back}
flashMode={RNCamera.Constants.FlashMode.on}
androidCameraPermissionOptions={{
title: 'Permission to use camera',
message: 'We need your permission to use your camera',
buttonPositive: 'Ok',
buttonNegative: 'Cancel',
}}
androidRecordAudioPermissionOptions={{
title: 'Permission to use audio recording',
message: 'We need your permission to use your audio',
buttonPositive: 'Ok',
buttonNegative: 'Cancel',
}}
captureAudio={true}
/>
) : (
<Video
source={{uri: this.state.video}}
style={{
position: 'absolute',
top: 0,
left: 0,
alignItems: 'stretch',
bottom: 0,
right: 0,
height: '90%',
}}
resizeMode="cover"
repeat={true}
paused={this.state.videoPaused}
/>
)}
</View>
);
}
static getDerivedStateFromProps(nextProps, prevState) {
return {
...prevState,
videoPaused: !nextProps.navigation.isFocused()
}
}
video = () => {
ImagePicker.openPicker({
mediaType: 'video',
}).then((video) => {
this.setState({
galleryVideo: 1,
video: video.path,
upload: true,
});
});
};
take30sVideo = async () => {
if (this.camera) {
try {
const options = {
quality: 2,
videoBitrate: 8000000,
maxDuration: 30,
};
const promise = this.camera.recordAsync(options);
this.setState({progress30: true});
this.value = setInterval(() => {
if (this.state.progressStatus <= 1) {
this.setState({progressStatus: this.state.progressStatus + 0.01});
}
}, 100);
if (promise) {
this.setState({recording: true});
const data = await promise;
this.setState({recording: false, upload: true, progress30: false});
console.log(data);
console.log('upload', this.state.upload);
}
} catch (error) {
console.log(error);
}
}
};
take60sVideo = async () => {
if (this.camera) {
try {
const options = {
quality: 2,
videoBitrate: 8000000,
maxDuration: 60,
};
const promise = this.camera.recordAsync(options);
this.setState({progress60: true});
this.value = setInterval(() => {
if (this.state.progressStatus60 <= 1) {
this.setState({
progressStatus60: this.state.progressStatus60 + 0.01,
});
}
}, 100);
if (promise) {
this.setState({recording: true});
const data = await promise;
this.setState({recording: false, upload: true, progress60: false});
console.log(data);
console.log('upload', this.state.upload);
}
} catch (error) {
console.log(error);
}
}
};
take15sVideo = async () => {
if (this.camera) {
try {
const options = {
quality: 2,
videoBitrate: 8000000,
maxDuration: 15,
};
const promise = this.camera.recordAsync(options);
this.setState({progress15: true});
this.value = setInterval(() => {
if (this.state.progressStatus15 <= 1) {
this.setState({
progressStatus15: this.state.progressStatus15 + 0.01,
});
}
}, 100);
if (promise) {
this.setState({recording: true});
const data = await promise;
this.setState({recording: false, upload: true, progress15: false});
console.log(data);
console.log('upload', this.state.upload);
}
} catch (error) {
console.log(error);
}
}
};
}
export default withNavigationFocus(Shoot);
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
backgroundColor: 'black',
},
preview: {
height: '90%',
justifyContent: 'flex-end',
alignItems: 'center',
},
capture: {
backgroundColor: '#e75480',
borderRadius: 40,
borderWidth: 3,
borderColor: 'red',
width: 60,
height: 60,
position: 'absolute',
bottom: 0,
justifyContent: 'center',
left: '45%',
alignContent: 'center',
},
});
I have already tried withNavigationFocus but it is not working,let me know if any other way is there,also let me know if anything else is required for clarification.
Any suggestion would be great.
I have finally resolved this issue by creating a function for next button and setting the state of paused to true whenever the screen navigates to the other screen.
Hope,that helps.
Setting the video screen as "fullScreenModal" worked for me:
("react-native": "0.71.2", "#react-navigation/native": "^6.1.3", "react-native-video": "^5.2.1")
react navigation stack definition:
function Stack() {
return (
<Stack.Navigator>
<Stack.Screen name="SomeScreen" component={SomeScreen} />
<Stack.Screen
name="FullScreenVideo"
component={FullScreenVideo}
options={{ headerShown: false, presentation: "fullScreenModal" }}
/>
</Stack.Navigator>;
)
}
FullScreenVideo.jsx
import React from "react";
import Video from "react-native-video";
import { StyleSheet } from "react-native";
export default function FullScreenVideo({ navigation, route }) {
const videoUri = route.params.uri;
return (
<Video
source={{ uri: videoUri }}
controls
onEnd={() => navigation.pop()}
style={styles.backgroundVideo}
/>
);
}
var styles = StyleSheet.create({
backgroundVideo: {
position: "absolute",
top: 0,
left: 0,
bottom: 0,
right: 0,
},
});
I think you also could killed or paused the video when the component will be unmounted:
// Class component
componentWillUnmount() {
videoRef.seek(0)
this.setState({isPaused: true})
}
OR
// functional component
useEffect(() => {
return () => {
videoRef.current.seek(0)
setIsPaused(true)
}
}, [])
You also can use methods from react native navigation:
Call a function when focused screen changes
I hope it’ll help someone
hi i want to draw an arrow every polyline
like this image :
read this post :
How to draw an arrow on every polyline segment on Google Maps V3
this is answer my question but this post for javascript
but i use it and this is my code:
<View style={{ height: hp('50%'), width: wp('100%') }}>
<MapView
provider={PROVIDER_GOOGLE}
onLayout={this.onMapLayout}
style={styles.containerMap}
initialRegion={{
latitude: this.props.data ? this.props.data[0].YPOINT : '',
longitude: this.props.data ? this.props.data[0].XPOINT : '',
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}} >
{this.state.isMapReady && <Polyline
strokeWidth={2}
strokeColor="red"
geodesic={true}
icons={
icon = { path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW },
offset = '100%'
}
coordinates={[...this.props.data.map((value, index) => {
return { latitude: value.YPOINT, longitude: value.XPOINT }
})]}
/>
}
</MapView>
</View>
but when run i get error 'google is not defined'.
UPDATE
this is function :
import React, { Component } from 'react'
import { Text, View, StyleSheet, ScrollView, AsyncStorage, ActivityIndicator, Alert, FlatList } from 'react-native'
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen';
//import arrowIcon from '../../../assets/images/icon/Arrow/090.ico'
import SegmentedControlTab from "react-native-segmented-control-tab";
import { Dropdown } from 'react-native-material-dropdown';
import { getTraceOfHardware } from '../../../Store/actions';
import { connect } from 'react-redux';
import MapView, { Marker, PROVIDER_GOOGLE, Polyline } from 'react-native-maps';
import Icon from 'react-native-vector-icons/Entypo';
var moment = require('jalali-moment');
let dataDay = [{
value: 'امروز',
}, {
value: 'یک روز پیش',
}, {
value: 'دو روز پیش',
}, {
value: 'سه روز پیش',
}, {
value: 'چهار روز پیش',
}, {
value: 'پنج روز پیش',
}, {
value: 'شش روز پیش',
}, {
value: 'هفت روز پیش',
},];
const airplin = <Icon name="aircraft" size={30}/>
class mainRoutsReport extends Component {
constructor () {
super()
this.state = {
selectedIndex: 0,
selectedIndices: [0],
customStyleIndex: 0,
daySelected: '',
isMapReady: false,
tableHead: ['Head', 'Head2', 'Head3', 'Head4', 'Head5', 'Head6', 'Head7', 'Head8', 'Head9'],
widthArr: [40, 60, 80, 100, 120, 140, 160, 180, 200],
data: [],
latlon: []
// tableData: [
// ['1', '2', '3', '4', '5', '6'],
// ['1', '2', '3', '4', '5', '6']
// ]
}
}
//GET UDID
_retrieveUDID = async () => {
try {
return await AsyncStorage.getItem('#IranTracking:UDID', (error, result) => { return result })
} catch (error) {
// Error retrieving data
console.log(error)
}
};
//GET TOKEN
_retrieveToken = async () => {
try {
return await AsyncStorage.getItem('#IranTracking:Token', (error, result) => { return result })
} catch (error) {
// Error retrieving data
console.log(error)
}
};
//This method creat XML to send action.js to get List of Hardware from SOAP
async _makXML(value, index) {
udid = await this._retrieveUDID()
token = await this._retrieveToken()
var yesterday = moment().locale('fa').subtract(index + 0, 'day').format('YYYY-MM-DD')
// console.log(yesterday)
let xml = `<?xml version="1.0" encoding="utf-8"?>\
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tra="http://Trackinguri.org/">\
<x:Header>\
<tra:SOAPHeaderContent>\
<tra:UserName></tra:UserName>\
<tra:Password></tra:Password>\
<tra:Token>${token}</tra:Token>\
<tra:UID>${udid}</tra:UID>\
</tra:SOAPHeaderContent>\
</x:Header>\
<x:Body>\
<tra:GetTraceByHardwareID>\
<tra:HardwareID>${this.props.navigation.state.params.HID}</tra:HardwareID>\
<tra:FromDate>${yesterday} 00:00:00</tra:FromDate>\
<tra:ToDate>${yesterday} 23:59:59</tra:ToDate>\
<tra:HijriDates>true</tra:HijriDates>\
<tra:Time_Zone>Tehran</tra:Time_Zone>\
<tra:Lang>fa</tra:Lang>\
</tra:GetTraceByHardwareID>\
</x:Body>\
</x:Envelope>`;
console.log(" xml to get Tarce reports " + xml)
this.props.getTraceOfHardware(xml)
}
componentWillMount() {
this._makXML()
this.props.getTraceOfHardware()
}
componentDidMount() {
}
//this function use for day
_HandelDay(value, index) {
// var yesterday = moment().locale('fa').subtract(index,'day').format('YYYY-MM-DD')
//console.log('index of drop down is : ' + value + ' \nindex is : '+ index + '\n and date is : ' + yesterday)
//Alert.alert(yesterday)
}
handleMultipleIndexSelect = (index: number) => {
const { selectedIndices } = this.state
if (selectedIndices.includes(index)) {
this.setState(prevState => ({
...prevState,
selectedIndices: selectedIndices.filter((i) => i !== index),
}))
} else {
this.setState(prevState => ({
...prevState,
selectedIndices: [
...selectedIndices,
index,
],
}))
}
}
handleCustomIndexSelect = (index: number) => {
this.setState(prevState => ({ ...prevState, customStyleIndex: index }))
}
onMapLayout = () => {
this.setState({ isMapReady: true });
}
_renderItem = ({ item, index }) => (
// console.log(item)
<View style={{ flex: 1, height: hp('15%'), flexDirection: 'row', backgroundColor: index % 2 ? '#f3f3f3' : '#dedede', marginHorizontal: 5, alignItems: 'center' }} >
<View style={{ width: wp('15%'), alignItems: 'center', }}>
<Text style={{ marginLeft: 4, fontFamily: 'IRANSansMobile', }}>{item.TRUCKSTATE}</Text>
</View>
<View style={{ width: wp('12%'), alignItems: 'center' }}>
<Text style={{ marginLeft: 4, fontFamily: 'IRANSansMobile', }}>{item.SPEED}</Text>
</View>
<View style={{ width: wp('50%'), alignItems: 'center' }}>
<Text style={{ marginLeft: 4, fontFamily: 'IRANSansMobile', }}>{item.POSDESCRIPTION}</Text>
</View>
<View style={{ width: wp('10%'), alignItems: 'center' }}>
<Text style={{ marginLeft: 4, fontFamily: 'IRANSansMobile', }}>{item.SENTDATE}</Text>
</View>
<View style={{ width: wp('10%'), alignItems: 'center' }}>
<Text style={{ marginLeft: 4, fontFamily: 'IRANSansMobile', }}>{index + 1}</Text>
</View>
</View>
);
_renderHeadr = () => (
<View style={{ flexDirection: 'row', alignContent: 'space-between', alignItems: 'center', backgroundColor: '#5e9dcb' }}>
<View style={{ borderWidth: 0.5, width: wp('15%'), alignItems: 'center', borderTopLeftRadius: 5 }}>
<Text style={{ fontSize: 15, fontFamily: 'IRANSansMobile', }}>وضعیت</Text>
</View>
<View style={{ borderWidth: 0.5, width: wp('12%'), alignItems: 'center' }}>
<Text style={{ fontSize: 15, fontFamily: 'IRANSansMobile', }}>سرعت</Text>
</View>
<View style={{ borderWidth: 0.5, width: wp('50%'), alignItems: 'center' }}>
<Text style={{ fontSize: 15, fontFamily: 'IRANSansMobile', }}>موقعیت</Text>
</View>
<View style={{ borderWidth: 0.5, width: wp('10%'), alignItems: 'center' }}>
<Text style={{ fontSize: 15, fontFamily: 'IRANSansMobile', }}>زمان</Text>
</View>
<View style={{ borderWidth: 0.5, width: wp('10%'), alignItems: 'center', borderTopRightRadius: 5 }}>
<Text style={{ fontSize: 15, fontFamily: 'IRANSansMobile', }}>ردیف</Text>
</View>
</View>
);
render() {
const { customStyleIndex } = this.state
//console.log(this.props.navigation.state.params.HID)
//console.log(this.props.data)
return (
<View style={{ width: wp('100%'), height: hp('100%') }}>
<Dropdown animationDuration={100}
dropdownMargins={{ min: 0, max: 0 }}
dropdownOffset={{ top: 0, left: 0 }}
style={{ textAlign: 'center' }}
containerStyle={{ textAlign: 'right', backgroundColor: '#fcee97', borderWidth: 0.5, borderRadius: 13, margin: 8 }}
absoluteRTLLayout={true}
data={dataDay}
dropdownPosition={-5}
onChangeText={(value, index) => this._makXML(value, index)}
value={dataDay[0].value} />
<SegmentedControlTab
values={['نمایش متنی', 'نمایش نقشه']}
selectedIndex={customStyleIndex}
onTabPress={this.handleCustomIndexSelect}
borderRadius={0}
tabsContainerStyle={{ height: 50, backgroundColor: '#F2F2F2' }}
tabStyle={{ backgroundColor: '#ffffff', borderWidth: 0, borderColor: 'transparent' }}
activeTabStyle={{ backgroundColor: '#5e9dcb', marginTop: 2 }}
tabTextStyle={{ color: '#000000', fontWeight: 'bold', fontFamily: 'IRANSansMobile' }}
activeTabTextStyle={{ color: '#ffffff', fontFamily: 'IRANSansMobile' }}
/>
{//table
customStyleIndex === 0
&&
<View style={{ paddingBottom: wp('20%') }}>
{this.props.isLoading ? <ActivityIndicator /> : <FlatList
ListHeaderComponent={this._renderHeadr}
stickyHeaderIndices={[0]}
data={this.props.data}
renderItem={this._renderItem}//({item})=>(this._renderItem)
keyExtractor={(item, index) => index.toString()}
/>}
</View>
}
{//Map
customStyleIndex === 1
&&
<View style={{ height: hp('50%'), width: wp('100%') }}>
<MapView
provider={PROVIDER_GOOGLE}
onLayout={this.onMapLayout}
style={styles.containerMap}
initialRegion={{
latitude: this.props.data ? this.props.data[0].YPOINT : '',
longitude: this.props.data ? this.props.data[0].XPOINT : '',
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}} >
{this.state.isMapReady &&
<Polyline
strokeWidth={2}
strokeColor="red"
geodesic={true}
icons={
icon = {airplin },
offset = '100%'
}
coordinates={[...this.props.data.map((value, index) => {
return { latitude: value.YPOINT, longitude: value.XPOINT }
})]}
/>
}
</MapView>
</View>
}
</View>
)
}
}
function mapStateToProps(state) {
console.log(state)
return {
data: state.GetTraceHardware.data,
isLoading: state.GetTraceHardware.isLoading,
error: state.GetTraceHardware.error
}
}
function mapDispatchToProps(dispatch) {
return {
getTraceOfHardware: (data) => dispatch(getTraceOfHardware(data))
}
}
export default connect(mapStateToProps, mapDispatchToProps)(mainRoutsReport);
Hi I am new to react native
I have mapview and FlatList in my screen like shown in the below image.
Now I want Mapview to be expanded when i click on it , like the below image
Here is my code
import React, { Component } from 'react';
import MapView, { PROVIDER_GOOGLE, Marker } from 'react-native-maps';
import { View, StyleSheet, Text, TouchableOpacity, Animated, Image } from 'react-native';
import { Actions } from 'react-native-router-flux';
import DoctorsList from './DoctorsList';
import colors from '../styles/colors';
var isHidden = true;
export default class FindDoctorMaps extends Component {
constructor(props) {
super(props);
this.state = {
bounceValue: new Animated.Value(500), //This is the initial position of the subview
buttonText: 'LIST VIEW',
printText: false,
markers: [{
title: 'hello',
coordinates: {
latitude: 17.452,
longitude: 78.3721
},
},
{
title: 'hi',
coordinates: {
latitude: 17.458,
longitude: 78.3731
},
},
{
title: 'gyp',
coordinates: {
latitude: 17.468,
longitude: 78.3631
},
},
{
title: 'nig',
coordinates: {
latitude: 17.568,
longitude: 78.3831
},
},
{
title: 'Yoy',
coordinates: {
latitude: 17.588,
longitude: 78.4831
},
}]
};
}
render() {
return (
<View style={{ flex: 1, backgroundColor: 'white' }} >
<MapView
provider={PROVIDER_GOOGLE}
region={{
latitude: 17.452,
longitude: 78.3721,
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
}}
style={styles.map}
showsUserLocation
followUserLocation
showsMyLocationButton
showsCompass
zoomEnabled
>
{this.state.markers.map(marker => (
<MapView.Marker
coordinate={marker.coordinates}
title={marker.title}
onPress={this.onMarkerPress}
/>
))}
</MapView>
<TouchableOpacity style={styles.filterContainer} onPress={Actions.morefilters}>
<View style={styles.filterStyle}>
<Image style={{ margin: 5 }} source={require('../assets/filters_icon.png')} />
<Text style={{ fontSize: 14, color: colors.darkBlue, fontWeight: 'bold', }}> Filters</Text>
</View>
</TouchableOpacity>
<View>
<TouchableOpacity >
<DoctorsList />
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
map: {
height: 200,
},
textViewStyle: {
fontSize: 14,
color: '#00539d',
fontWeight: 'bold',
margin: 20
},
subView: {
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
backgroundColor: '#FFFFFF',
height: 500,
},
filterContainer: {
top: '20%',
right: 0,
alignSelf: 'flex-end',
position: 'absolute'
},
filterStyle: {
flexDirection: 'row',
backgroundColor: colors.white,
borderRadius: 8,
height: 30,
width: '60%',
alignItems: 'center',
justifyContent: 'center'
}
});
Can any one please help me how to expand Mapview by clicking on it.
or else please share some useful links so that i would be helpful for me
this.state = {
....
showMapFullScreen: false
....
}
render() {
....
<MapView
....
style={height: showMapFullScreen ? "100%" : 200 }
onPress={() => this.setState({ showMapFullScreen : true }) }
....
>
....
<TouchableOpacity
onPress={() => this.setState({ showMapFullScreen : false }) }>
<DoctorsList />
</TouchableOpacity>
.......
}
You can toggle the map height with a flag like shown above. When the user clicks on the map the height becomes full screen when he/she clicks on the list the map's height is reduced and gives space to the list to render.
For some reason 2 Amazon Kindles that I have for testing running the latest updates (Android 5.1.1) is producing just a solid green colour when capturing with React-Native-Camera.
I've also tested on my Xiaomi Mi6, a Mi5 and also an Asus Zen 8" Tablet, all working fine, but the Kindle produces this weired outcome... What's really strange is the viewfinder is fine, it looks as if it'll take a picture but doesn't. The Front Facing camera is fine also.
Using react-native-camera: ^1.1.4
Capture.js
import React, { Component } from 'react';
import { StyleSheet, Text, View, ActivityIndicator } from 'react-native';
import { Avatar } from 'react-native-elements';
import { RNCamera } from 'react-native-camera';
import { inject, observer } from 'mobx-react/native';
import ImagePicker from 'react-native-image-crop-picker';
let Type = null;
const typeArr = [
{ Name: 'Front', Type: RNCamera.Constants.Type.front },
{ Name: 'Back', Type: RNCamera.Constants.Type.back },
{ Name: null, Type: RNCamera.Constants.Type.back },
];
const styles = StyleSheet.create({
entryTitle: {
fontSize: 22,
fontWeight: '700',
},
container: {
flex: 1,
flexDirection: 'column',
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
},
loading: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(255, 255, 255, 0.8)',
},
});
#inject('store')
#observer
export default class Capture extends Component {
constructor(props) {
super(props);
this.state = { Type: RNCamera.Constants.Type.back, CaptureInProgress: false };
Type =
this.props.navigation.state.params.Type == null
? null
: this.props.navigation.state.params.Type;
}
state = {
Type: typeArr.find(element => element.Name === Type).Type,
};
barcodeScanned(response) {
this.props.store.CaptureStore.captureData = response.data;
this.props.navigation.state.params.AfterCapture();
this.props.navigation.goBack();
}
takePicture = async function () {
if (this.camera) {
this.setState({ CaptureInProgress: true });
const options = { quality: 0.5, base64: true, fixOrientation: true };
const data = await this.camera.takePictureAsync(options);
this.props.store.CaptureStore.captureData = data.base64;
this.props.navigation.state.params.AfterCapture();
this.setState({ CaptureInProgress: false });
this.props.navigation.goBack();
}
};
openGallery() {
ImagePicker.openPicker({
width: 300,
height: 400,
cropping: true,
includeBase64: true,
}).then((image) => {
this.props.store.CaptureStore.captureData = image.data;
this.props.navigation.state.params.AfterCapture();
this.props.navigation.goBack();
});
}
switchCamera() {
if (this.state.Type === RNCamera.Constants.Type.back) {
this.setState({ Type: RNCamera.Constants.Type.front });
} else {
this.setState({ Type: RNCamera.Constants.Type.back });
}
}
renderTakePhotoButton() {
if (this.props.navigation.state.params.Mode === 'photo') {
return (
<View
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Avatar
medium
rounded
icon={{ name: 'refresh', color: 'grey', type: 'font-awesome' }}
onPress={() => this.switchCamera()}
activeOpacity={1}
/>
<Avatar
large
rounded
icon={{ name: 'camera', color: 'grey' }}
onPress={() => this.takePicture()}
activeOpacity={1}
/>
<Avatar
medium
rounded
icon={{ name: 'folder-open-o', color: 'grey', type: 'font-awesome' }}
onPress={() => this.openGallery()}
activeOpacity={1}
/>
</View>
);
}
return null;
}
render() {
return (
<View style={styles.container}>
<View
style={{
height: '10%',
padding: 10,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Text style={styles.entryTitle}>{this.props.navigation.state.params.Title}</Text>
</View>
<View
style={{
height: this.props.navigation.state.params.Mode === 'photo' ? '75%' : '90%',
flexDirection: 'column',
}}
>
<RNCamera
ref={(ref) => {
this.camera = ref;
}}
style={styles.preview}
barCodeTypes={
this.props.navigation.state.params.Mode === 'qr'
? [RNCamera.Constants.BarCodeType.qr]
: []
}
type={this.state.Type}
// flashMode={RNCamera.Constants.FlashMode.on}
permissionDialogTitle="Permission to use camera"
permissionDialogMessage="We need your permission to use your camera phone"
onBarCodeRead={response => this.barcodeScanned(response)}
/>
</View>
{this.renderTakePhotoButton()}
{this.state.CaptureInProgress && (
<View style={styles.loading}>
<ActivityIndicator size="large" color="#0000ff" />
</View>
)}
</View>
);
}
}
Specifically, it all happens in 'takePicture', the afterCapture just handles the consumption of the base64 that is temporarily in the CaptureStore...
Fixed in React-Native-Camera 1.1.5