So I am basically looking for the error and what I am doing wrong,
I got a data with diffrent key for each, and I am trying to get the data of the activeRow,
for some reason I got undefined for some reason, what is going on? Thanks!
I am getting undefined after trying to log the "this.props.index" I already called constructor(props) and super(props), So I have no idea why why I am trying to log my prop it says undefined instead of giving me the index or the item...
there is my render!
render() {
const swipeSettings = {
autoClose: true,
buttonWidth: 130,
onClose: (secId, rowId, direction) => {
if (this.state.activeRowKey != null) {
this.setState({ activeRowKey: null })
}
},
onOpen: (secId, rowId, direction) => {
this.setState({ activeRowKey: this.props.index })
console.log(this.state.activeRowKey)
},
right: [
{
onPress: () => {
},
text: 'Verify', type: 'default', backgroundColor: 'lime', color: 'black', component: (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'column',
}}
>
<Ionicons name="md-checkmark" size={40} />
</View>
)
}
],
left: [
{
onPress: () => {
},
text: '', type: 'default', backgroundColor: '#e6e6e6', color: 'black', component: (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'column',
}}
>
<Ionicons style={{ color: 'green' }} name="ios-call" size={40} />
</View>
)
}
],
rowId: this.props.index,
sectionId: 1
};
if (this.state.loading) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<ActivityIndicator />
</View>
);
}
return (
<View style={{ flex: 1, backgroundColor: 'grey' }}>
<SearchBar
placeholder="Type Here..."
lightTheme
round
height={60}
onChangeText={text => this.searchFilterFunction(text)}
autoCorrect={false}
value={this.state.value}
/>
<FlatList
data={this.state.data}
renderItem={({ item,index }) => (
<Swipeout {...swipeSettings}>
<ListItem
keyExtractor={this.keyExtractor}
index={index}
titleStyle={{ textAlign: 'center', fontWeight: 'bold', color: 'black', fontSize: 20, height: 60, maxHeight: 35, justifyContent: 'center' }}
title={`${item.guestname}`}
/>
</Swipeout>
)}
keyExtractor={item => item.key}
contentContainerStyle={{ margin: 5, textAlign: 'center', }}
ItemSeparatorComponent={this.renderSeparator}
/>
<SafeAreaView style={{ height: 100, backgroundColor: '#3271e7', justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity style={{ justifyContent: 'center', alignItems: 'center' }}>
<Ionicons style={styles.imagestyle} size={60} name="ios-barcode" />
</TouchableOpacity>
</SafeAreaView>
</View>
);
}
At the place your are trying to recover this.props.index you don't have the value yet i recomend passing the open and rowid props to your Swipeout and recover the index as it is:
render() {
const swipeSettings = {
autoClose: true,
buttonWidth: 130,
onClose: (secId, rowId, direction) => {
if (this.state.activeRowKey != null) {
this.setState({ activeRowKey: null })
}
},
right: [
{
onPress: () => {
},
text: 'Verify', type: 'default', backgroundColor: 'lime', color: 'black', component: (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'column',
}}
>
<Ionicons name="md-checkmark" size={40} />
</View>
)
}
],
left: [
{
onPress: () => {
},
text: '', type: 'default', backgroundColor: '#e6e6e6', color: 'black', component: (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'column',
}}
>
<Ionicons style={{ color: 'green' }} name="ios-call" size={40} />
</View>
)
}
],
sectionId: 1
};
if (this.state.loading) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<ActivityIndicator />
</View>
);
}
return (
<View style={{ flex: 1, backgroundColor: 'grey' }}>
<SearchBar
placeholder="Type Here..."
lightTheme
round
height={60}
onChangeText={text => this.searchFilterFunction(text)}
autoCorrect={false}
value={this.state.value}
/>
<FlatList
data={this.state.data}
renderItem={({ item, index }) => (
<Swipeout
{...swipeSettings}
onOpen={(secId, rowId, direction) => {
this.setState({ activeRowKey: index })
console.log(this.state.activeRowKey)
}
}
rowId={index}
>
<ListItem
keyExtractor={this.keyExtractor}
index={index}
titleStyle={{ textAlign: 'center', fontWeight: 'bold', color: 'black', fontSize: 20, height: 60, maxHeight: 35, justifyContent: 'center' }}
title={`${item.guestname}`}
/>
</Swipeout>
)}
keyExtractor={item => item.key}
contentContainerStyle={{ margin: 5, textAlign: 'center', }}
ItemSeparatorComponent={this.renderSeparator}
/>
<SafeAreaView style={{ height: 100, backgroundColor: '#3271e7', justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity style={{ justifyContent: 'center', alignItems: 'center' }}>
<Ionicons style={styles.imagestyle} size={60} name="ios-barcode" />
</TouchableOpacity>
</SafeAreaView>
</View>
);
}
Related
I have a custom DrawerContent component and I am unable to navigate to a screen from it using navigator.navigate('DrawerHelp').
I am still getting this error and I really have no idea how to fix it.
I am trying to navigate from the Help button to its own component called DrawerHelp.
issue The action 'NAVIGATE' with payload {"name":"DrawerHelp"} was not handled by any navigator
This is my code below.
function DrawerComponent() {
return (
<Drawer.Navigator
drawerContentOptions={{activeBackgroundColor: '#efefef', activeTintColor: '#000000'}}
initialRouteName="Tabs"
drawerStyle={{ backgroundColor:'#ffffff', width:'85%', paddingBottom: 50 }}
drawerContent={
props => ( <CustomDrawerContent {...props} /> )
}>
<Drawer.Screen name="Dashboard" component={Tabs} options={{
drawerIcon: config => <Ionicons name={'ios-home'} size={18} color={'#444'} headerTitle="AAA" />,
}} />
<Drawer.Screen name="Help" component={DrawerHelp}
options={{
drawerIcon: config => <Ionicons name={'ios-people-circle-outline'} size={18} color={'#444'}/>,
}}
/>
</Drawer.Navigator>
);
}
export function CustomDrawerContent (props) {
const [ tabs, setTabs ] = useState([
{
name: 'Help',
icon: 'ios-call',
borderColor: '#e7c53f',
backgroundColor: '#fff',
color: '#e7c53f',
fontWeight: '500'
},{
name: 'Share',
icon: 'ios-megaphone',
borderColor: '#e7c53f',
backgroundColor: '#fff',
color: '#e7c53f',
fontWeight: '500'
},{
name: 'Logout',
icon: 'ios-log-out',
borderColor: '#e7c53f',
backgroundColor: '#fff',
color: '#e7c53f',
fontWeight: '500'
}
]);
return (
<DrawerContentScrollView {...props}>
<DrawerItemList {...props} />
<View style={{ padding: 15 }}>
<View style={{
flexDirection: 'row',
justifyContent: 'space-between',
height: 50,
alignItems: 'center'
}}>
{
tabs.map((tab) => {
return (
<TouchableOpacity
key={tab.name}
style={{
height: '100%',
flex: .32,
alignItems: 'center',
borderWidth: .5,
borderColor: tab.borderColor,
backgroundColor: tab.backgroundColor,
borderRadius: 10,
flexDirection: 'row',
justifyContent: 'space-evenly'
}}
onPress={() => {
if(tab.name == 'Logout') {
// navigation.toggleDrawer();
}
if(tab.name == 'Share') {
// onShare();
}
if(tab.name == 'Help') {
props.navigation.navigate('DrawerHelp');
}
}}>
<Ionicons name={tab.icon} size={18} style={{ color: tab.color }} />
<Text style={{ color: tab.color, fontWeight: tab.fontWeight }}>{trans(tab.name, cntx.lang)}</Text>
</TouchableOpacity>
)
})
}
</View>
</View>
</DrawerContentScrollView>
);
}
It is not working because you have defined DrawerComponent with name 'Help'
<Drawer.Screen name="Help" component={DrawerHelp}
options={{drawerIcon: config => <Ionicons name={'ios-people-circle-outline'} size={18} color={'#444'}/>
if(tab.name == 'Help') {
props.navigation.navigate('DrawerHelp'); <== Change here to Help not DrawerHelp
}
I have a problem when i try to launch the react-native app on Android Emulators and Android
Devices.
On IOS Emulator, it works fine and the message doesn't appear.
I'm trying to make modification but the message appears.
The message : "TypeError: Attempted to assign to readonly property."
My code :
import React, {useEffect, useState} from 'react';
import {
Dimensions,
SafeAreaView,
View,
TouchableOpacity,
Text,
StyleSheet,
Platform,
Image,
KeyboardAvoidingView,
} from 'react-native';
import NetInfo from '#react-native-community/netinfo';
import {DrawerActions} from '#react-navigation/native';
import {Icon} from 'native-base';
import {ScrollView} from 'react-native-gesture-handler';
import Logo from '../assets/logo.svg';
import {useSelector} from 'react-redux';
import ImageMunition from '../assets/photo-munitions.jpg';
import FondB from '../assets/fond.jpg';
let Accueil = (props) => {
let [orientation, setOrientation] = useState('PORTRAIT');
let [connexion, setIsConnected] = useState(null);
let [type, setType] = useState(null);
let identifiant = useSelector((state) => state.identifiant);
let cc = false;
useEffect(() => {
if (!cc) {
Dimensions.addEventListener('change', ({window: {width, height}}) => {
if (width < height) {
setOrientation('PORTRAIT');
} else {
setOrientation('LANDSCAPE');
}
});
}
return () => {
cc = true;
};
}, []);
useEffect(() => {
NetInfo.addEventListener(handleConnectivityChange);
}, [NetInfo]);
let handleConnectivityChange = (state) => {
setIsConnected(state);
};
if (connexion) {
setTimeout(() => {
setIsConnected(null);
}, 2000);
}
useEffect(() => {
props.navigation.setOptions({
headerShown: true,
header: () => {
return (
<SafeAreaView
style={[
orientation === 'PORTRAIT'
? styles.headerPortrait
: styles.headerPaysage,
]}>
<View
style={
orientation === 'PORTRAIT'
? styles.logoPortrait
: styles.logoPaysage
}>
<Logo
height={orientation === 'PORTRAIT' ? 150 : 100}
width={orientation === 'PORTRAIT' ? 150 : 150}
/>
</View>
<View
style={
orientation === 'PORTRAIT'
? styles.MenuPortrait
: styles.MenuPaysage
}>
<TouchableOpacity
style={
orientation === 'PORTRAIT'
? styles.IconPortrait
: styles.IconPaysage
}
onPress={() =>
props.navigation.dispatch(DrawerActions.toggleDrawer())
}>
<Icon
name="menu"
type="MaterialIcons"
style={{color: '#C69D74', fontSize: 60}}
/>
</TouchableOpacity>
</View>
</SafeAreaView>
);
},
});
}, []);
if (type) {
setTimeout(() => {
setType(null);
}, 4000);
}
if (connexion === 'Connexion') {
setTimeout(() => {
setIsConnected(null);
}, 4000);
}
return (
<KeyboardAvoidingView
keyboardVerticalOffset={10}
enabled={true}
style={{
display: 'flex',
backgroundColor: 'white',
flexDirection: 'column',
justifyContent: 'center',
flex: 1,
zIndex: 10,
}}>
<View>
<Image
source={FondB}
style={{
width: Dimensions.get('screen').width,
zIndex: 10,
position: 'absolute',
}}
/>
</View>
<ScrollView
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
style={{zIndex: 100}}
contentContainerStyle={{
alignContent: 'center',
alignItems: 'center',
}}>
<Image
source={ImageMunition}
style={[
orientation === 'PORTRAIT'
? styles.ImagePortrait
: styles.ImagePaysage,
{zIndex: 10, position: 'absolute'},
]}
/>
<View
style={{
width: Dimensions.get('screen').width,
justifyContent: 'center',
alignContent: 'center',
flex: 1,
zIndex: 100,
}}>
<View
style={
orientation === 'PORTRAIT'
? styles.BodyPortrait
: styles.BodyPaysage
}>
<View
style={
orientation === 'PORTRAIT'
? styles.ParaPortrait
: styles.ParaPaysage
}>
<Text
style={{
textAlign: 'center',
fontSize: 15,
color: 'white',
fontFamily: 'OpenSans-SemiBold',
zIndex: 100,
}}>
Bienvenue sur l'application SIDAM qui vous permet de bénéficier
d'une
</Text>
<View
style={{
width: Dimensions.get('screen').width / 1.7,
marginTop: 10,
}}>
<Text
style={{
fontSize: 33,
fontFamily: 'OpenSans-ExtraBold',
textAlign: 'center',
textTransform: 'uppercase',
color: 'white',
zIndex: 100,
}}>
extension
</Text>
</View>
<View style={{margin: 0, padding: 0}}>
<Text
style={{
fontSize: 33,
fontFamily: 'OpenSans-ExtraBold',
textAlign: 'center',
textTransform: 'uppercase',
color: 'white',
zIndex: 100,
}}>
de garantie
</Text>
</View>
<View style={{margin: 0, padding: 0}}>
<Text
style={{
fontSize: 33,
fontFamily: 'OpenSans-ExtraBold',
textAlign: 'center',
textTransform: 'uppercase',
color: 'white',
zIndex: 100,
}}>
de votre arme
</Text>
</View>
</View>
</View>
</View>
<View
style={
orientation === 'PORTRAIT'
? styles.Para2Portrait
: styles.Para2Paysage
}>
<View
style={{
zIndex: 100,
justifyContent: 'center',
alignContent: 'center',
display: 'flex',
alignItems: 'center',
width: Dimensions.get('screen').width,
}}>
{connexion &&
connexion.isConnected &&
connexion.type === 'cellular' && (
<Text
style={{
color: 'red',
fontSize: 16,
fontFamily: 'Poppins-Regular',
textAlign: 'center',
justifyContent: 'center',
alignContent: 'center',
alignItems: 'center',
}}>
Vous êtes maintenant connecté
</Text>
)}
{connexion &&
connexion.isWifiEnabled &&
connexion.type !== 'cellular' && (
<Text
style={{
color: 'red',
fontSize: 16,
fontFamily: 'Poppins-Regular',
textAlign: 'center',
justifyContent: 'center',
alignContent: 'center',
alignItems: 'center',
}}>
Vous êtes maintenant connecté en Wifi
</Text>
)}
{connexion && !connexion.isConnected && !connexion.isWifiEnabled && (
<Text
style={{
color: 'red',
fontSize: 16,
fontFamily: 'Poppins-Regular',
position: 'absolute',
textAlign: 'center',
}}>
Vous n'êtes pas connecté
</Text>
)}
</View>
<Text
style={{
color: '#636A28',
textAlign: 'center',
fontSize: 27,
fontFamily: 'OpenSans-ExtraBold',
marginTop:
Platform.OS === 'android'
? Dimensions.get('window').height > 700
? 0
: 10
: 0,
}}>
ACCÉDER À VOTRE RÂTELIER VIRTUEL
</Text>
<TouchableOpacity
style={
orientation === 'PORTRAIT'
? styles.ButtonPortrait
: styles.ButtonPaysage
}
onPress={() => props.navigation.navigate('Connexion')}>
<Text
style={{
color: 'white',
fontSize: 17,
textTransform: 'uppercase',
fontFamily: 'OpenSans-SemiBold',
}}>
Se connecter
</Text>
</TouchableOpacity>
</View>
{!identifiant && (
<View style={{marginTop: 15}}>
<TouchableOpacity
style={
orientation === 'PORTRAIT'
? styles.ButtonPortraitB
: styles.ButtonPaysageB
}
onPress={() => props.navigation.navigate('Inscription')}>
<Text
style={{
textAlign: 'center',
color: 'white',
fontSize: 17,
textTransform: 'uppercase',
fontFamily: 'OpenSans-SemiBold',
}}>
Créer un compte
</Text>
</TouchableOpacity>
</View>
)}
<View style={{marginTop: 15}}>
<TouchableOpacity
style={
orientation === 'PORTRAIT'
? styles.ButtonBisPortrait
: styles.ButtonBisPaysage
}
onPress={() => props.navigation.navigate('Reglement')}>
<Text style={{textAlign: 'center', color: 'black'}}>Réglement</Text>
</TouchableOpacity>
</View>
<View style={{marginTop: 20}}></View>
</ScrollView>
</KeyboardAvoidingView>
);
};
let styles = StyleSheet.create({
logoPortrait: {
...Platform.select({
ios: {
marginLeft: 15,
alignContent: 'center',
justifyContent: 'center',
},
android: {marginLeft: 15},
}),
},
logoPaysage: {
...Platform.select({
ios: {
margin: 0,
padding: 0,
alignContent: 'center',
justifyContent: 'center',
},
android: null,
}),
},
headerPortrait: {
width: Dimensions.get('screen').width,
display: 'flex',
backgroundColor: 'white',
flexDirection: 'row',
borderBottomColor: 'black',
alignContent: 'center',
borderBottomWidth: 1,
alignItems: 'center',
zIndex: 5000,
...Platform.select({
android: {
height: Dimensions.get('screen').height / 7,
},
ios: {
height: Dimensions.get('screen').height / 6,
},
}),
},
headerPaysage: {
width: Dimensions.get('screen').width,
display: 'flex',
flexDirection: 'row',
alignContent: 'center',
alignItems: 'center',
borderBottomColor: 'black',
borderBottomWidth: 1,
backgroundColor: 'white',
zIndex: 100,
...Platform.select({
android: {
width: Dimensions.get('screen').width,
height: Dimensions.get('screen').height / 7,
},
ios: {
width: Dimensions.get('screen').width,
height: Dimensions.get('screen').height / 4,
},
}),
},
MenuPortrait: {
zIndex: 100,
position: 'absolute',
width: Dimensions.get('screen').width,
paddingBottom: 10,
alignSelf: 'center',
...Platform.select({
ios: {},
android: {},
}),
},
MenuPaysage: {
zIndex: 100,
position: 'absolute',
width: Dimensions.get('screen').width,
alignSelf: 'center',
...Platform.select({
ios: {
paddingBottom: 30,
},
android: {
paddingBottom: 30,
},
}),
},
IconPaysage: {
zIndex: 100,
alignItems: 'flex-end',
marginTop: 35,
...Platform.select({
android: null,
ios: null,
}),
},
IconPortrait: {
zIndex: 100,
alignItems: 'flex-end',
marginRight: 10,
...Platform.select({
android: {
marginTop: 15,
},
ios: {
marginTop: 50,
},
}),
},
ButtonPortrait: {
backgroundColor: '#636A28',
width: Dimensions.get('screen').width / 2,
height: 40,
justifyContent: 'center',
alignContent: 'center',
alignItems: 'center',
marginTop: 30,
...Platform.select({
android: null,
ios: null,
}),
},
ButtonPaysage: {
backgroundColor: '#636A28',
width: Dimensions.get('screen').width / 3,
height: 40,
justifyContent: 'center',
alignContent: 'center',
alignItems: 'center',
marginTop: 30,
...Platform.select({
android: null,
ios: null,
}),
},
ButtonBisPortrait: {
width: Dimensions.get('screen').width / 2,
height: 40,
justifyContent: 'center',
alignContent: 'center',
alignItems: 'center',
marginTop: 0,
...Platform.select({
android: null,
ios: null,
}),
},
});
export default Accueil;
Thanks you
TL;DR
It is uncertain that when will the audio file be fetched and given to the trackplayer. So i need a way that will detect the change that the file has been fetched and duration value is now available. I tried playing around with Async/await but it still fails to deliver the duration value on time to the slider.
I am developing an RN app that can stream the audio files that are currently stored in my firebase storage. I am facing difficulty in updating the slider's maximumValue. Since the song takes a couple of seconds to get fetched from firebase, the (total) duration value of the song file given by the react-native-track-player is undefiend and consequently the play button's onPress function setState(duration) sets the new tracklength state as undefined. And this is set as the maximumValue for the slider, which in turn gives the error as shown in the screenshot.
What can i do such that, when the TrackPlayer.getState() (a method from the ProgressComponent) changes its value to 'playing' or 'Ready', the application automatically rerenders with the correct duration value without giving the error.
I have used React-native-slider and React-native-Track-player
/* eslint-disable react-native/no-inline-styles */
import React from 'react';
import { Text, View, Image, SafeAreaView, TouchableOpacity, Platform, StatusBar, Dimensions, Modal, Button } from 'react-native';
import Slider from 'react-native-slider';
import Moment from 'moment';
import DeviceInfo from 'react-native-device-info';
import { FontAwesome5, Feather, Entypo } from '#expo/vector-icons';
import { Surface, Card, Badge } from 'react-native-paper';
import TrackPlayer, { ProgressComponent, getPosition } from 'react-native-track-player';
import storage from '#react-native-firebase/storage';
export default class MusicPlayer extends ProgressComponent {
componentWillMount() {
TrackPlayer.setupPlayer().then(async () => {
await TrackPlayer.add({
// url: 'https://sampleswap.org/mp3/artist/5101/Peppy--The-Firing-Squad_YMXB-160.mp3',
url: (await storage().ref('Songs/01 - Luck Aazma - www.downloadming.com.mp3').getDownloadURL()).toString(),
});
}
).then(console.log('aaaaaaaaaaaaaaaaaaaaaaa ' + this.getS().then(res => console.log(res))));
// .then(async () => {
// var dur = (await TrackPlayer.getDuration()).toString();
// this.setState({ trackLength: dur });
// });
// const temp = await TrackPlayer.getState();
// if (temp === TrackPlayer.STATE_READY) { console.log('its ready here') }
}
// componentDidMount() {
// this.interval = setInterval(
// () => {
// this.forceUpdate;
// }, 3500
// );
// }
// componentWillUnmount() {
// clearInterval(this.interval);
// }
constructor(props) {
super(props);
this.state = {
trackLength: 300,
timeElapsed: '0:00',
timeRemaining: '5:00',
optionsVisible: false,
curr_time: 0,
isPlaying: false,
t_state: this.getS(),
};
}
seekTime = seconds => {
this.setState({ timeElapsed: Moment.utc(seconds * 1000).format('m:ss') });
TrackPlayer.seekTo(seconds);
this.setState({ timeRemaining: Moment.utc((this.state.trackLength - seconds) * 1000).format('m:ss') });
};
setCurr = seconds => {
return Moment.utc(seconds * 1000).format('m:ss');
};
getS = async () => {
return await TrackPlayer.getState();
}
render() {
return (
<SafeAreaView style={{ backgroundColor: '#2d545e', flex: 1, paddingTop: (DeviceInfo.hasNotch && Platform.OS === 'android') ? StatusBar.currentHeight : 0 }}>
<View style={{ margin: 3, flex: 1 }}>
<TouchableOpacity
style={{ alignSelf: 'flex-end', marginRight: 10 }}
onPress={this.toggleOverlay} >
<Entypo name="dots-three-vertical" size={24} color="white" />
</TouchableOpacity>
{/* playlist name and album name */}
<View style={{ alignItems: 'center', marginTop: -25 }}>
<Text style={{ color: '#FFFFFF', fontSize: 10 }}>PLAYLIST</Text>
<Text style={{ color: '#FFFFFF', fontFamily: 'sans-serif', fontWeight: '500' }}>Album_name_here</Text>
</View>
{/* song image/ thumbnail zone */}
<Surface raised style={{ marginTop: 30, height: 200, width: 200, alignSelf: 'center', elevation: 50, borderRadius: 30 }}>
<Image source={{ uri: 'https://a10.gaanacdn.com/images/albums/61/161/crop_480x480_161.jpg' } || require('../../assets/images/temp.jpeg')} style={{ height: 200, width: 200, borderRadius: 30, alignSelf: 'center' }} />
</Surface>
{/* song name and artist name */}
<View style={{ marginTop: 25, flexDirection: 'column', alignItems: 'center' }}>
<Text style={{ color: '#FFFFFF', fontFamily: 'sans-serif', fontWeight: 'bold', fontSize: 20 }}>Song_Name_here</Text>
<Text style={{ color: '#FFFFFF', fontFamily: 'sans-serif', fontWeight: '500', marginTop: 3 }}>artist_name_here</Text>
</View>
{/* slider component only */}
<View style={{ flexDirection: 'column', alignItems: 'center', marginTop: 8 }}>
<Slider
minimumValue={0}
value={this.state.position}
animationType="timing"
maximumValue={this.state.trackLength}
trackStyle={{ width: Dimensions.get('screen').width - 50, height: 4 }}
thumbStyle={{ height: 20, width: 20, backgroundColor: '#fff' }}
thumbTouchSize={{ width: 100, height: 40 }}
minimumTrackTintColor="#000000"
onSlidingComplete={seconds => { console.log(seconds); this.seekTime(seconds); }}
/>
<View style={{ width: Dimensions.get('screen').width - 35, backgroundColor: '#', flexDirection: 'row', justifyContent: 'space-between' }}>
<Text style={{ flex: 1 }}>{this.setCurr(this.state.position)}</Text>
<Text style={{ alignSelf: 'flex-end' }}>{this.setCurr(this.state.trackLength)}</Text>
</View>
</View>
{/* repeat, back, play, forward and shuffle button */}
<View style={{ width: '95%', height: 70, backgroundColor: '#', alignSelf: 'center', margin: 15, flexDirection: 'row' }}>
<TouchableOpacity style={{ flex: 1, height: 30, width: 10, alignSelf: 'center', justifyContent: 'space-between', alignItems: 'center' }}>
<Feather
name="repeat"
size={30}
color="#000000"
style={{ alignItems: 'center' }}
/>
</TouchableOpacity>
<TouchableOpacity style={{ flex: 1, height: 30, width: 10, alignSelf: 'center', justifyContent: 'space-between' }} onPress={() => TrackPlayer.skipToPrevious()}>
<FontAwesome5 name="backward" size={32} color="#242320" style={{ alignSelf: 'center' }} />
</TouchableOpacity>
{
// this.state.t_state === TrackPlayer.STATE_READY &&
!this.state.isPlaying && <TouchableOpacity
style={{ flex: 1, height: 50, alignSelf: 'center', justifyContent: 'space-between', alignItems: 'center' }}
onPress={async () => {
TrackPlayer.play().then(this.setState({ isPlaying: true })).then(async () => {
var dur = (await TrackPlayer.getDuration()).toString();
this.setState({ trackLength: dur });
});
}}
>
<FontAwesome5
name="play"
size={38}
color="#000000"
style={{ marginTop: 5 }}
/>
</TouchableOpacity>}
{this.state.isPlaying && <TouchableOpacity style={{ flex: 1, height: 50, alignSelf: 'center', justifyContent: 'space-between', alignItems: 'center' }} onPress={() => TrackPlayer.pause().then(this.setState({ isPlaying: false }))}>
<FontAwesome5
name="pause"
size={38}
color="#000000"
style={{ marginTop: 5 }}
/>
</TouchableOpacity>}
<TouchableOpacity style={{ flex: 1, height: 30, width: 10, alignSelf: 'center', justifyContent: 'space-between' }} onPress={() => TrackPlayer.skipToNext()}>
<FontAwesome5 name="forward" size={32} color="#242320" style={{ alignSelf: 'center' }} />
</TouchableOpacity>
<TouchableOpacity style={{ flex: 1, height: 30, width: 10, alignSelf: 'center', justifyContent: 'space-between', alignItems: 'center' }}>
<Entypo
name="shuffle"
size={30}
color="#000000"
style={{ alignItems: 'center' }}
/>
</TouchableOpacity>
</View>
{/* up next section */}
<Surface raised style={{ width: '95%', backgroundColor: 'black', alignSelf: 'center', height: 70, borderRadius: 10, marginTop: 5 }}>
<Card.Title
style={{ backgroundColor: 'white', flex: 1, borderRadius: 10 }}
title={'Song Name here'}
titleStyle={{ margin: 25, padding: 0 }}
left={() =>
<Image
style={{ width: 50, height: 50, borderRadius: 10, alignSelf: 'flex-start', alignItems: 'flex-start' }}
source={require('../../assets/images/temp.jpeg')}
/>
}
leftStyle={{ alignItems: 'flex-start', margin: -10, padding: 0 }}
right={() => <Badge children={'Next'} size={30} style={{ width: 70, backgroundColor: 'black', borderRadius: 5, marginRight: 10 }} />}
/>
</Surface>
</View>
</SafeAreaView>
);
}
}
Sorry for the messy code but the comments would help a bit in navigating to the main parts like Slider and Play Button
Error:
My Error from the slider
For those who might require an answer to this, I solved the problem using React Hooks. React Native Track Player has a v2 update, in which the converting the above class component to functional component did the trick. It gives a rather accurate results then before. Refer to the docs here.
I'm building an app which uses the Map method to build several different components. I have a scrollview which contains the whole page. Currently, the scrollView won't expand to contain everything despite trying what is seemingly every bit of advice online.
I have tried having the scrollview be inside another view but that still doesn't work as well as a combination of different flex configurations. Does anyone know why this page in particular isn't working. I have compared it to other pages and there is seemingly no reason as to why the flex does not extend.
Thanks
render(){
return (
<ScrollView contentContainerStyle={{flexGrow: 1}} >
<View style={styles.pageContainer}>
<View style={styles.photoShowcase }>
{
this.state.images.map((item, key) => (
<Image key = {key} source={{uri: item}} style = {{width: 200, height: 200}} />
))
}
</View>
<View style = {styles.cameraContainer}>
<TouchableHighlight onPress={this.handleChoosePhoto}>
<Icon type='font-awesome' name='photo' size={60} />
</TouchableHighlight>
<Icon type='font-awesome' name='camera' size={120} />
<Icon type='font-awesome' name='map-o' size={60} />
</View>
<View style= {styles.detailsContainer}>
<View >
<TextInput onChangeText={(text) => {this.setState({title: text})}} style = {styles.title} >New Day Title </TextInput>
</View>
<View style = {styles.description}>
<TextInput onChangeText={(text) => {this.setState({description: text})}} multiline={true}>Description for the text goes here</TextInput>
</View>
</View>
<View style = {styles.friendsContainer}>
<View>
<Text style = {styles.friendsSectionTitle}>I spent today with: </Text>
</View>
<ScrollView horizontal= {true}>
<View style={styles.peopleContainer}>
{
this.state.friends.map((item, key) => (
<View key={key} >
<TouchableHighlight >
<PersonEntryBox name={item.name} backgroundImageToUse={item.image} style = {styles.smallBox} functionToRun = {() => {this.state.selectedFriends.push(item)}} />
</TouchableHighlight>
</View>
))
}
</View>
</ScrollView>
</View>
<View style={{height: '40%', width: '100%'}}>
<MapView
style={{...StyleSheet.absoluteFillObject}}
initialRegion={{
latitude: 45.5209087,
longitude: -122.6705107,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
onPress={this.handlePress}
>
{this.state.markers.map((marker) => {
return (
<Marker {...marker} >
<View style={styles.marker}>
<Text style = {styles.markerText}>{marker.cost}</Text>
</View>
</Marker>
)
})}
</MapView>
</View>
<View style = {styles.ratingsButtonContainer}>
<RateTheDayBox style={styles.badDay} dayRating="Bad" onClick={() => {this.state.rating ="red"; this.storeDay()}}></RateTheDayBox>
<RateTheDayBox style={styles.okayDay} dayRating="Okay" onClick={() => {this.state.rating = "yellow"; this.storeDay()}}></RateTheDayBox>
<RateTheDayBox style={styles.greatDay} dayRating="Great" onClick={() => {this.state.rating = "green"; this.storeDay()}}></RateTheDayBox>
</View>
</View>
</ScrollView>
);
}}
const styles = StyleSheet.create({
pageContainer: {
paddingTop: 50,
alignItems: 'center',
flex: 1,
},
mapContainer:{
flex: 1,
},
marker: {
backgroundColor: "#550bbc",
padding: 5,
borderRadius: 5,
},
text: {
color: '#FFF',
fontWeight: "bold",
},
photoShowcase: {
flex: 1,
flexDirection: 'row',
alignItems: 'flex-start',
justifyContent: 'flex-end',
zIndex: 0,
height: 200
},
cameraContainer: {
flexDirection: 'row',
paddingTop:20,
paddingLeft: '5%',
paddingRight: '5%',
width: '100%',
height: '25%',
alignItems: 'center',
justifyContent: 'space-around',
},
iconStyles: {
marginLeft: 10,
color: 'red',
},
detailsContainer: {
width: '100%',
height: '35%',
},
title: {
paddingLeft: 10,
fontSize: 40,
textDecorationLine: 'underline',
},
description: {
paddingLeft: 11,
paddingTop: 10,
},
friendsContainer: {
width: '100%',
height: '20%',
},
boxContainers: {
flexDirection: 'row',
},
friendsSectionTitle: {
paddingLeft: 10,
fontSize: 30,
},
ratingsButtonContainer: {
width: '100%',
height: '20%',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between'
},
badDay: {
backgroundColor: 'red',
},
okayDay: {
backgroundColor: 'yellow',
},
greatDay: {
backgroundColor: 'green',
},
peopleContainer: {
paddingTop: 10,
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center',
alignItems: 'center' ,
width: '100%',
height: '100%',
},
});
EDIT: For anyone suffering from the same issue, REMOVE PERCENTAGES FROM HEIGHTS. This fixed this issue for me.
Maybe just use style instead of contentContainerStyle ? the doc says :
These styles will be applied to the scroll view content container which wraps all of the child views
So maybe here is your problem, you're not applying the flexGrow to the scrollView but to its wrapper
I'm facing an issue that button at bottom of FLatList's footer(here ListFooterComponent). I tried all solutions but I failed.
My output https://i.stack.imgur.com/Hn4PW.jpg
My code
_renderItem(rowData) {
return(
<View style={{ flex: 1}}>
<View style={s.cate_detail_box}>
<TouchableOpacity activeOpacity={0.9} style={{height: 190}}>
<Image source={{uri: rowData.item.images[0].src}} style={s.img}/>
</TouchableOpacity>
<View style={{padding: 5}}>
<View activeOpacity={0.9} style={{flexDirection: 'row', justifyContent: 'space-between'}}>
<View>
<CapitalizedText style={s.cate_detail_title}>{rowData.item.title}</CapitalizedText>
<Text style={s.cate_detail_price}>{'₹' + rowData.item.variants[0].price}</Text>
</View>
<TouchableOpacity activeOpacity={0.7} >
<Icon size={icon_size} color="#aaa" name="turned-in-not" />
</TouchableOpacity>
</View>
</View>
</View>
</View>
);
}
_render_Footer = () => {
return (
<View style = { s.footerStyle }>
<TouchableOpacity
activeOpacity = { 0.7 }
style = { s.btn_load_more }
onPress = { this.fetch_more_data_from_server }
>
<Text style = { s.btn_load_more_txt }>Load More</Text>
</TouchableOpacity>
</View>
)
}
render() {
return(
<ScrollView showsVerticsalScrollIndicator={false} style={s.category_detail_scroll} contentContainerStyle={{ flexGrow: 1}}>
<View>
{
this.state.product_detail.length <= 0 ?
<ActivityIndicator color = '#bc2b78' size = "large" style={{alignItems: 'center', justifyContent: 'center'}} />
:
<FlatList
contentContainerStyle={s.list}
keyExtractor = {( item, index ) => index.toString() }
data = { this.state.product_detail }
renderItem = {(rowData) => this._renderItem(rowData)}
ListFooterComponent = { this._render_Footer }
/>
}
</View>
</ScrollView>
);
}
CSS
cate_detail_box: {
margin: 2,
width: 180,
backgroundColor: '#fff',
borderWidth: 1,
borderColor: '#aaa',
},
cate_detail_title: {
color: '#666',
fontSize: font_small,
},
cate_detail_price: {
fontSize: 15,
color: '#666',
justifyContent: 'center',
alignItems: 'center',
},
category_detail_scroll: {
flex: 1,
backgroundColor: 'rgba(243,229,245, 0.6)',
},
footerStyle:{
padding: 7,
width: '100%',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#000',
},
btn_load_more: {
padding: 7,
backgroundColor: '#F44336',
borderRadius: 5,
},
Any help is appreciated.
Thank you.
Please apply this
footerStyle: {
flex: 1
alignItems: 'center'
}
And remove all styles for TouchableOpacity and Text