Need Help React Native Image Header Scroll View - reactjs

I wanted to add a Image Header Scroll View for my Project. I used the below code and which gives me the error
"Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined."
I tried everything i could but i didn't find a solution. Also I totally don't understand why this error is popping.
import React, {Component} from 'react';
import {
StyleSheet,
Text,
View,
Image,
Dimensions,
StatusBar,
} from 'react-native';
import * as Animatable from 'react-native-animatable';
import {Header} from 'react-navigation-stack';
import HeaderImageScrollView, {
TriggeringView,
} from 'react-native-image-header-scroll-view';
const MIN_HEIGHT = Header.HEIGHT;
const MAX_HEIGHT = 250;
const styles = StyleSheet.create({
title: {
fontSize: 20,
},
section: {
padding: 20,
borderBottomWidth: 1,
borderBottomColor: '#cccccc',
backgroundColor: 'white',
},
sectionTitle: {
fontSize: 18,
fontWeight: 'bold',
},
titleContainer: {
flex: 1,
alignSelf: 'stretch',
justifyContent: 'center',
alignItems: 'center',
},
navTitleView: {
height: MIN_HEIGHT,
justifyContent: 'center',
alignItems: 'center',
paddingTop: 16,
opacity: 0,
},
navTitle: {
color: 'white',
fontSize: 18,
backgroundColor: 'transparent',
},
sectionLarge: {
height: 600,
},
});
class TvShow extends Component {
constructor() {
super();
this.state = {showNavTitle: false};
}
render() {
return (
<View style={{flex: 1}}>
<StatusBar barStyle="light-content" />
<HeaderImageScrollView
maxHeight={MAX_HEIGHT}
minHeight={MIN_HEIGHT}
maxOverlayOpacity={0.6}
minOverlayOpacity={0.3}
fadeOutForeground
renderHeader={() => (
<Text>Hiiii</Text>
)}
renderFixedForeground={() => (
<Animatable.View
style={styles.navTitleView}
ref={navTitleView => {
this.navTitleView = navTitleView;
}}>
<Text style={styles.navTitle}>
Hii
</Text>
</Animatable.View>
)}
renderForeground={() => (
<View style={styles.titleContainer}>
<Text>Hii</Text>
</View>
)}>
<TriggeringView
style={styles.section}
onHide={() => this.navTitleView.fadeInUp(200)}
onDisplay={() => this.navTitleView.fadeOut(100)}>
<Text style={styles.title}>
<Text>Hii</Text>, ( 1998)
</Text>
</TriggeringView>
<View style={styles.section}>
<Text style={styles.sectionTitle}>Overview</Text>
<Text>Hii</Text>
</View>
<View style={[styles.section, styles.sectionLarge]}>
</View>
</HeaderImageScrollView>
</View>
);
}
}
export default TvShow;

it's a library problem, use the version 0.10.3
"react-native-image-header-scroll-view": "0.10.3"

Related

How to use auto scroll view in react native with dote?

here is my code
App.js
import React from 'react'
import { Image, StyleSheet, TouchableOpacity, Dimensions, Text, View } from 'react-native'
import { scale, verticalScale } from "react-native-size-matters"
import { RFPercentage} from 'react-native-responsive-fontsize';
import { FlatList } from 'react-native';
const dummyData =
[{
title: 'Get instant loans with approvals',
uri: 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTWo3YRChZ3ADpZ7rEfQu1RvBOu9NMWZIMZBaH-a1CArXqx6nLX',//require('../img/1page.jpg'),
id: 1
},
// {
// title: 'Get money in wallet or bank account',
// uri: 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQN0NcV2epN147CiVfr_VAwsbU3VO8rJU0BPphfU9CEsVWa-kRX',//require('../img/1page.jpg'),
// id: 2
// },
// {
// title: 'Refer & earn exciting gifts',
// uri: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSUbS4LNT8rnIRASXO6LGFSle7Mhy2bSLwnOeqDMivYTb2cgTJg',//require('../img/1page.jpg'),
// id: 3
// }
]
const Home = ({ navigation }) => {
const renderItem=({item})=>{
return(
<View>
<Image source={{uri:item.uri}}style={styles.img} />
<View style={styles.dotView}>
<View style={styles.dot}/>
<View style={styles.dot}/>
<View style={styles.dot}/>
</View>
<Text style={styles.text}>{item.title}</Text>
</View>
)
}
return (
<View style={styles.contanier}>
<View style={styles.imgView}>
<Image source={require('../img/homelogo.png')} style={styles.logo} />
</View>
<View style={{marginBottom:8}}>
<FlatList
data={dummyData}
renderItem={renderItem}
keyExtractor={item => item.id}
/>
</View>
<View style={styles.btnview}>
<TouchableOpacity style={styles.btn}
onPress={() => navigation.navigate("PermissionPage")}
>
<Text style={styles.btntext}>Get Started</Text>
</TouchableOpacity>
</View>
</View>
)
}
export default Home;
const styles = StyleSheet.create({
contanier: {
flex: 1,
backgroundColor: '#fff',
},
imgView: {
marginTop: verticalScale(10),
marginLeft: 20,
},
logo: {
width: scale(70),
height: verticalScale(70),
borderRadius: 50,
// position: 'absolute'
},
btnview: {
alignItems: 'center',
justifyContent: 'center',
marginTop:10,
},
btn: {
width: scale(250),
height: verticalScale(55),
borderRadius: 5,
backgroundColor: '#2192FF',
alignItems: 'center',
justifyContent: 'center',
},
btntext: {
fontSize: RFPercentage(3.20),// fontSize: RFValue(17, 680),
color: '#fff',
fontWeight: '600',
fontFamily: 'Roboto'
},
img:{
width:scale(300),
height:verticalScale(450),
},
text:{
fontSize:RFPercentage(3),
fontWeight:'bold',
color:'#000',
textAlign:'center'
},
dotView:{
flexDirection:'row',
justifyContent:'center',
marginBottom:8
},
dot:{
width:scale(8),
height:verticalScale(8),
backgroundColor:'#2192ff',
borderRadius:20,
marginLeft:5
}
})
here is output I want
https://imgur.com/a/yvR5XgM
I'm creating new app in app home page have auto scroll img but I don't know how to use it and do it
I'm fine some lib but i don't use any lib I want without lib.
I'm seen may qustion on internet but I'm not find soution what I want
any one can help me ?

I have a issue when i try to write react navigation

I have begun the React Navigation. I have some issue about my project and i wish everybody can support me.
In the app.js, i code:
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
TextInput,
TouchableOpacity,
StatusBar,
} from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
class HomeScreen extends Component {
static navigationOptions = {
header: null
}
render() {
return (
<View style={styles.container}>
<StatusBar backgroundColor="#1e90ff"
barStyle="light-content" />
<Text style={styles.welcome}>Login To My App</Text>
<TextInput
style={styles.input}
placeholder="Username" />
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
/>
<View style={styles.btnContainer}>
<TouchableOpacity style={styles.userBtn}
onPress{() => this.props.navigation.navigate('Details')}
>
<Text style={styles.btnTxt}>Login</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.userBtn}
onPress{() => this.props.navigation.navigate('Details')}>
<Text style={styles.btnTxt}>Signup</Text>
</TouchableOpacity>
</View>
</View>
)
}
}
class DetailsScreen extends Component {
static navigationOptions = {
title: 'My App',
headerRight: <View/>
}
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
</View>
);
}
}
const RootStack = createStackNavigator({
Home: HomeScreen,
Detail: DetailsScreen
},
{
intialRouteName: 'Home',
defaultNavigationOptions: {
headerStyle: {
backgroundColor: "#1e90ff"
}
},
headerTintColor: "#fff",
headerTitleStyle: {
textAlign: "center",
flex: 1,
}
}
);
const AppContainer = createAppContainer(RootStack);
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<AppContainer />
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
backgroundColor: "lightskyblue",
},
welcome: {
fontSize: 30,
textAlign: "center",
margin: 10,
color: "lightgray",
},
input: {
width: "90%",
backgroundColor: "#fff",
padding: 15,
marginBottom: 10,
marginLeft: 20,
},
btnContainer: {
flexDirection: "row",
justifyContent: "space-between",
width: "90%",
marginLeft: 20,
},
userBtn: {
backgroundColor: "#FFD700",
padding: 15,
width: "45%"
},
btnTxt: {
fontSize: 18,
textAlign: "center",
}
})
Detail: I try to write the code based on the youtube https://www.youtube.com/watch?v=bUesHGYxSLg&list=PLQWFhX-gwJblNXe9Fj0WomT0aWKqoDQ-h&index=4&ab_channel=PradipDebnath and i cannot understand the mistake i met.
When i tried to run by npx react-native run-android in terminal, the warning appeared.
Result: Error failed to instal the app. Make sure you have the Android development environmet set up.
Error: Command fail: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081.
Question: How can i fix the mistake? Because when i star a new file, it did not haave the mistake. Thank for your attention.

Invariant Violation: Element type is invalid - React Native

Git hub repo is here : https://github.com/AliYar-Khan/react-navigation.git
When I going to run my react native app on my Genny motion emulator this error displayed in red background area.
Invariant Violation: Element type is invalid: expected a string (for
built-in components) or a class/function (for composite components)
but got: object. You likely forgot to export your component from the
file it's defined in.
this is the Login.js inside the 'src/pages/' folder
import * as React from 'react';
import {
TouchableOpacity ,
View ,
StyleSheet ,
ScrollView ,
Text ,
TextInput ,
Dimensions ,
Alert
} from 'react-native';
import { connect } from 'react-redux';
import Logo from '../components/Logo';
import clickLogin from '../redux/actions/loginActions';
import { Icon } from 'react-native-elements';
const { height } = Dimensions.get('window');
class Login extends React.Component {
constructor(props){
super(props);
this.state = {
username : '' ,
password : '' ,
screenHeight: height ,
pendingLoginReqest : false
}
}
onContentSizeChange = (contentWidth, contentHeight) => {
this.setState({ screenHeight: contentHeight });
};
Login = () => {
// firebase.auth().signInWithEmailAndPassword(this.state.username , this.state.password)
// .then(()=>{
// }, (error) => {
// Alert.alert(error.message);
// })
this.props.clickLogin(this.state);
};
render() {
const scrollEnabled = this.state.screenHeight > height;
const {navigate} = this.props.navigation;
return (
<ScrollView style={{ flex: 1 }}
scrollEnabled={scrollEnabled}
onContentSizeChange={this.onContentSizeChange}
>
<View style={styles.container}>
<Logo />
<TextInput style={styles.textinput}
returnKeyType='next'
underlineColorAndroid='rgba(0,0,0,0)'
placeholder='Email or Username'
keyboardType='email-address'
autoCapitalize='none'
autoCorrect = {false}
onChangeText={data => this.setState({ username : data })}
onSubmitEditing={() => this.passwordInput.focus()}
placeholderTextColor = '#ffffff'
/>
<TextInput style={styles.textinput}
underlineColorAndroid='rgba(0,0,0,0)'
placeholder='Password'
secureTextEntry
returnKeyType='go'
onChangeText={data => this.setState({ password : data})}
ref= {(input) => this.passwordInput = input}
placeholderTextColor = '#ffffff'
/>
<TouchableOpacity style={styles.buttonLogin}
onPress={this.Login}>
<Text style={styles.loginButtonText}>Login</Text>
</TouchableOpacity>
<View style={styles.socialLoginButtons}>
<Icon.Button name='facebook' size={15} backgroundColor='#1c313a'>
<Text style={{fontFamily:'Arial', fontSize:15, fontSize: 16,
fontWeight: '500', color: '#ffffff',
textAlign: 'center'}}
>
Login with Facebook
</Text>
</Icon.Button>
</View>
<View style={styles.socialLoginButtons}>
<Icon.Button name='twitter' size={20} backgroundColor='#1c313a'>
<Text style={{fontFamily:'Arial', fontSize:15,fontSize: 16,
fontWeight: '500',color: '#ffffff',textAlign: 'center'}}>
Login with Twitter
</Text>
</Icon.Button>
</View>
<View style={styles.signuptextcont}>
<Text style={styles.signuptext}>Don't have an Account?</Text>
<TouchableOpacity style={styles.signupbtn} onPress= {()=>navigate('Signup')}>
<Text style={styles.signuptext}>Signup</Text>
</TouchableOpacity>
</View>
</View>
</ScrollView>
);
}
}
// const mapStateToProps = state => {
// return {
// }
// }
const mapDispatchToProps = (dispatch) => {
return {
clickLogin : (user) => dispatch(clickLogin(user))
}
}
export default connect(null,mapDispatchToProps)(Login);
const styles = StyleSheet.create({
container:{
flex: 1,
alignItems: 'center',
justifyContent:'flex-start'
},
text:{
marginVertical:15,
color: 'rgba(255,255,255,0.7)',
fontSize: 20
},
textinput:{
width: 300,
backgroundColor : 'rgba(255,255,255,0.3)',
borderRadius: 25,
paddingHorizontal: 16,
color: '#ffffff',
marginVertical: 10
},
signuptext:{
color: 'rgba(255,255,255,0.6)',
fontSize: 16
},
socialLoginButtons:{
paddingVertical: 5,
marginVertical: 10,
width: 300,
backgroundColor: '#1c313a'
},
signuptextcont:{
flexGrow: 1,
alignItems: 'flex-end',
flexDirection: 'row',
justifyContent:'center',
paddingVertical: 16
},
buttonLogin:{
width: 300,
backgroundColor: '#1c313a',
borderRadius: 25,
paddingVertical: 12,
marginVertical: 5
},
signupbtn:{
color : '#ffffff',
fontSize: 16,
fontWeight: '500',
paddingHorizontal:10
}
});
and Logo.js is as follows :
import * as React from 'react';
import { Image, View, StyleSheet, Text } from 'react-native';
import { TextInput } from 'react-native-gesture-handler';
export default class Logo extends React.Component {
render() {
return (
<View style={styles.LogoContainer}>
<Image style={{width: 50, height: 50}}
source={require('../img/favicon.png')}/>
<Text style={styles.LogoText}>Welcome to the App.</Text>
</View>
);
}
}
const styles = StyleSheet.create({
LogoContainer:{
alignItems: 'center',
justifyContent:'center',
marginTop:50,
marginVertical:5,
marginBottom:5
},
LogoText:{
marginVertical:20,
color: 'rgba(255,255,255,0.7)',
fontSize: 20
}
});
From the stacktrace the problem is in Login.js line 82 :
<View style={styles.socialLoginButtons}>
<Icon.Button name='facebook' size={15} backgroundColor='#1c313a'>
<Text style={{fontFamily:'Arial', fontSize:15, fontSize: 16,
fontWeight: '500', color: '#ffffff',
textAlign: 'center'}}
>
Login with Facebook
</Text>
</Icon.Button>
</View>
Here you are using Icon.Button after checking the react-native-elements docs there is no Icon.Button which means that it will be undefined and throw that error

React Native elevation StyleSheet not working in FlatList

I'm trying to style my renderItem in FlatList but elevation not working properly. Is there anything I'm wrong or this is a React Native issue?
I tested ListView too but it still not working properly
This is TodoItem component
import React, { Component } from 'react'
import { Text, View, StyleSheet } from 'react-native'
const styles = StyleSheet.create({
container: {
height: 60,
backgroundColor: 'white',
borderRadius: 10,
shadowColor: '#000',
shadowOffset: { width: 2, height: 2 },
shadowOpacity: 0.4,
shadowRadius: 2,
elevation: 3,
justifyContent: 'center',
paddingHorizontal: 30,
marginBottom: 12
},
text: {
fontSize: 18,
fontWeight: '400',
color: '#080808'
}
})
export default class TodoItem extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.text}> {this.props.text} </Text>
</View>
)
}
}
And this is where I call it in FlatList
<FlatList
data={this.props.items}
renderItem={(item) => <TodoItem key={item.index} text={item.item} />}
/>
The point is that elevation works properly if I don't use FlatList like this
<TodoItem text="Hello world" />
What I excepted
What I see
Most issues like this are caused by styling that is applied to your surrounding view or the row that you are trying to render.
If you add a marginHorizontal: 10 to the styles.container for the row that should probably do it for you.
Here is a simplified example where the edges of the row are not cut off. It has a couple of tweaks to make it work, using state.items instead of props.items and changing the style name for the TodoItem to itemContainer. It should give you an idea of how to implement it.
import * as React from 'react';
import { Text, View, StyleSheet, FlatList } from 'react-native';
import { Constants } from 'expo';
export default class App extends React.Component {
state = {
items: [
'Hello'
]
}
render() {
return (
<View style={styles.container}>
<FlatList
data={this.state.items}
renderItem={(item) => <TodoItem key={item.index} text={item.item} />}
/>
</View>
);
}
}
class TodoItem extends React.Component {
render() {
return (
<View style={styles.itemContainer}>
<Text style={styles.text}> {this.props.text} </Text>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight + 10,
backgroundColor: '#ecf0f1',
},
itemContainer: {
marginHorizontal: 10,
height: 60,
backgroundColor: 'white',
borderRadius: 10,
shadowColor: '#000',
shadowOffset: { width: 2, height: 2 },
shadowOpacity: 0.4,
shadowRadius: 2,
elevation: 3,
justifyContent: 'center',
paddingHorizontal: 30,
marginBottom: 12
},
text: {
fontSize: 18,
fontWeight: '400',
color: '#080808'
}
});
Here is a snack showing it working https://snack.expo.io/#andypandy/flatlist-with-elevation-on-rows

React Native (android) , components overlapping with shadow issue

I am using a custom component with image and text. The image is relative to the text. Please see the screenshot.
image 1
image 2.
I have used the TouchableOpacity component as root view for that.
In screenshots when long press on the component, two views are overlapping with shadow. It looks ugly when long press.
Please see the code below for reusable component.
'use strict';
import React, {Component} from 'react';
import {
StyleSheet,
Text,
View,
TouchableOpacity,
Image,
} from 'react-native';
export default class ExampleButton extends Component {
constructor (props) {
super (props);
}
_handleOnPress = () => {
console.log('pressed!!!');
};
render () {
console.log (this.props);
return (
<TouchableOpacity
onPress={this.handleOnPress}
>
<View style={styles.btnCompContainer}>
<View
style={{
backgroundColor: '#FFF',
justifyContent: 'center',
borderRadius: 30,
height: 50,
width: '100%',
}}
>
<Text style={styles.btnTxt}>{this.props.buttonText}</Text>
</View>
<View style={[styles.btnElmContainer]}>
<Image
style={[{height: 30, width: 30,resizeMode:'stretch'}]}
source={this.props.image}
/>
</View>
</View>
</TouchableOpacity>
);
}
}
const styles = StyleSheet.create ({
btnCompContainer: {
flexDirection: 'row',
alignItems: 'center',
height: 60,
marginLeft: 10,
marginRight: 20,
},
btnElmContainer: {
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
width: 60,
height: 60,
backgroundColor:'#fff',
borderRadius: 30,
shadowColor: '#000000',
shadowOffset: {
width: 1,
height: 1,
},
elevation:5,
shadowRadius: 2,
shadowOpacity: 0.3,
},
btnTxt: {
marginLeft: 80,
color: '#9e9e9e',
fontSize: 16,
fontWeight: 'bold',
textAlign: 'left',
},
});
Here I am using this reusable component in code.
'use strict';
import React, {Component} from 'react';
import {
Animated,
StyleSheet,
Text,
TextInput,
View,
Image,
ImageBackground,
TouchableOpacity,
Button,
StatusBar,
Easing
} from 'react-native';
// Custom Components
const searchBGImg = require('../assets/search-bg-kit.png');
const houseLogo = require('../Resources/house.png');
import ExampleButton from './components/common/example-button';
export default class TypeSelect extends Component<Props> {
// Navigation Option
static navigationOptions = {
header: null
}
constructor() {
super();
this.state = {
visible: false,
x: new Animated.Value(-100),
};
}
slide = () => {
Animated.spring(this.state.x, {
toValue: 0,
easing: Easing.easeOutBack
}).start();
this.setState({
visible: true,
});
};
gotoSearch = () =>{
this.props.navigation.navigate('DocSearch')
}
componentDidMount(){
this.slide();
}
render() {
return (
<View style={styles.container}>
<ImageBackground source={searchBGImg} style={styles.imgBG}>
<View style={{alignItems:'center', marginBottom:20}}>
<Image style={{height:57, width:69, marginBottom:12}} source={houseLogo} />
</View>
<View>
<Animated.View
style={[styles.slideView, {
transform: [
{
translateX: this.state.x
}
]
}]}>
<ExampleButton image={houseLogo} buttonText={'Click here'} />
<ExampleButton image={houseLogo} buttonText={'Click here'} />
</Animated.View>
</View>
</ImageBackground>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
imgBG:{
flex: 1,
flexDirection: "column",
justifyContent:"center",
width: "100%",
height: "100%"
}
})
It is working fine in iOS, but it's not working in android up to the mark. Please help me to work it in android.
Thanks in advance.
You should use renderToHardwareTextureAndroid prop on <View /> component.
In your example like this:
<View style={styles.btnCompContainer} renderToHardwareTextureAndroid >
<View
style={{
backgroundColor: '#FFF',
justifyContent: 'center',
borderRadius: 30,
height: 50,
width: '100%',
}}
>
<Text style={styles.btnTxt}>{this.props.buttonText}</Text>
</View>
<View style={[styles.btnElmContainer]}>
<Image
style={[{height: 30, width: 30,resizeMode:'stretch'}]}
source={this.props.image}
/>
</View>
</View>

Resources