How to put a lot of numbers in an array and than use them in flatlist? - react-native

I got this bunch of buttnos and i need to make a horizontal flatlist in react native and i always get some error so can someone help me how to do that? I need to put these buttons in an array so i can put tham in that flatlist i need to make but i am stuck here :D i am new to reactnative so if someone can help me thanks <3
<View style={{flexDirection: 'row', paddingHorizontal: 10, paddingTop: 5}}>
<View style={{width: '15%', paddingRight: 5}}>
<TouchableOpacity
style={[styles.buttonText]}
activeOpacity = {.5}
onPress={ ()=>this.setState({...this.state, location: 'details'}) }>
<Text style={styles.buttonText}>Details</Text>
</TouchableOpacity>
</View>
<View style={{width: '15%', paddingRight: 5}}>
<TouchableOpacity
style={[styles.buttonText]}
activeOpacity = {.5}
onPress={ ()=>this.setState({...this.state, location: 'users'}) }>
<Text style={styles.buttonText}>Users</Text>
</TouchableOpacity>
</View>
<View style={{width: '15%', paddingRight: 5}}>
<TouchableOpacity
style={[styles.buttonText]}
activeOpacity = {.5}
onPress={ ()=>this.setState({...this.state, location: 'assets'}) }>
<Text style={styles.buttonText}>Assets</Text>
</TouchableOpacity>
</View>
<View style={{width: '15%', paddingRight: 5}}>
<TouchableOpacity
style={[styles.buttonText]}
activeOpacity = {.5}
onPress={ ()=>this.setState({...this.state, location: 'sites'}) }>
<Text style={styles.buttonText}>Sites</Text>
</TouchableOpacity>
</View>
<View style={{width: '15%', paddingRight: 5}}>
<TouchableOpacity
style={[styles.buttonText]}
activeOpacity = {.5}
onPress={ ()=>this.setState({...this.state, location: 'cards'}) }>
<Text style={styles.buttonText}>Cards</Text>
</TouchableOpacity>
</View>
</View>

I didn't make the full array, but this should give you the idea:
const buttons = [{title: "Users", location: "users"},{title: "Details", location: "details"}]
<View style={styles.container}>
<FlatList
horizontal
data={buttons}
keyExtractor={(item) => item.location}
renderItem={({item}) =>
<TouchableOpacity
style={[styles.buttonText]}
activeOpacity = {.5}
onPress={ ()=>this.setState({...this.state, location: item.location}) }>
<Text style={styles.buttonText}>{item.title}</Text>
</TouchableOpacity>
}
/>
</View>
If you titles and locations were always just capitalized versions of each other, you could simplify the array even further.

The exact code example is available directly on first load, on the flatlist documentation page.
import React from 'react';
import { SafeAreaView, View, FlatList, StyleSheet, Text, StatusBar } from 'react-native';
const DATA = [
{
id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
title: 'First Item',
},
{
id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
title: 'Second Item',
},
{
id: '58694a0f-3da1-471f-bd96-145571e29d72',
title: 'Third Item',
},
];
const Item = ({ title }) => (
<View style={styles.item}>
<Text style={styles.title}>{title}</Text>
</View>
);
const App = () => {
const renderItem = ({ item }) => (
<Item title={item.title} />
);
return (
<SafeAreaView style={styles.container}>
<FlatList
data={DATA}
renderItem={renderItem}
keyExtractor={item => item.id}
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: StatusBar.currentHeight || 0,
},
item: {
backgroundColor: '#f9c2ff',
padding: 20,
marginVertical: 8,
marginHorizontal: 16,
},
title: {
fontSize: 32,
},
});
export default App;
You just need to add the props horizontal in the Flatlist component to make it horizontal.

Related

React Native RenderItem not working with custom renderItem

I created a custom renderItem using the React Native documentation as an example and it is not working, however, when using a simple component (commented in the script), it is working perfectly. I have tried to change some things around, but I can't make it work.
For the flatlist, I based my code on the react native example at https://reactnative.dev/docs/flatlist, using the flat-list-simple example, calling the function in the render item as renderItem={Function} but react-native does not recognize it, I appreciate any guidance on what I could change or if I am doing the whole thing wrong, thank you!
import { StyleSheet, Text, View, TouchableOpacity, FlatList } from 'react-native'
import React from 'react'
import Ionicons from 'react-native-vector-icons/Ionicons';
import VisitasHeader from './VisitasHeader';
const VisitasCard = ({visitas,titulo}) => {
// renderItem for FlatList
const CardFunction = (item) => {
<View style={{marginBottom:10}}>
<View style={styles.card_top}>
<View style={styles.holder}>
<View style={styles.icon}>
<Ionicons
name='ios-people-circle-sharp'
color='white'
size={48}
/>
</View>
<View style={styles.visitante}>
<Text style={styles.text_nombre}>{item.nombre} </Text>
<Text style={styles.text_cedula}>e-0000001</Text>
<View>
<Text style={styles.text_fecha}>2 de enero de 2022</Text>
</View>
</View>
</View>
</View>
<View style={styles.card_bottom}>
<TouchableOpacity style={styles.button_accept}>
<Text style={styles.button_text}>Aceptar</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button_reject}>
<Text style={styles.button_text}>Rechazar</Text>
</TouchableOpacity>
</View>
</View>
}
return (
<FlatList
ListHeaderComponent={<VisitasHeader title={titulo} />}
data={visitas}
keyExtractor={item => item.id}
renderItem={CardFunction}
// renderItem={({item}) => <View><Text>{item.nombre}</Text></View>} WORKS PERFECT WHEN USING THIS
ListEmptyComponent={<Text style={{textAlign:'center',paddingTop:10}}>No tiene visitas por aprobar.</Text>}
/>
)
}
export default VisitasCard
const styles = StyleSheet.create({
button_accept:{
backgroundColor:'green',
// margin:12,
padding:10,
borderRadius:12,
},
button_text:{
color:'white',
fontWeight:'bold',
},
button_reject:{
backgroundColor:'red',
// margin:12,
padding:10,
borderRadius:12,
},
card_bottom:{
height:50,
flexDirection:'row',
alignItems:'center',
justifyContent:'center',
borderWidth:1,
borderColor:'#3959ea',
borderBottomLeftRadius:8,
borderBottomRightRadius:8,
justifyContent:'space-evenly'
},
card_top:{
height:100,
backgroundColor:'#3959ea',
borderTopLeftRadius:8,
borderTopRightRadius:8,
alignItems:'center',
justifyContent:'center',
},
holder:{
flexDirection:'row',
},
icon:{
padding:10,
alignItems:'center',
margin:12,
},
text_cedula:{
color:'white',
fontSize:18,
textTransform:'uppercase',
fontWeight:'600',
},
text_nombre:{
color:'white',
fontSize:24,
textTransform:'capitalize',
fontWeight:'800',
// ellipsizeMode:'head',
// numberOfLines:1,
},
text_fecha:{
color:'white'
},
visitante:{
flex:2,
justifyContent:'center',
alignItems:'flex-start',
}
})
try add { item } and add return
const CardFunction = ({ item }) => {
return (
<View style={{ marginBottom: 10 }}>
<View style={styles.card_top}>
<View style={styles.holder}>
<View style={styles.icon}>
<Ionicons
name="ios-people-circle-sharp"
color="white"
size={48}
/>
</View>
<View style={styles.visitante}>
<Text style={styles.text_nombre}>{item.nombre} </Text>
<Text style={styles.text_cedula}>e-0000001</Text>
<View>
<Text style={styles.text_fecha}>2 de enero de 2022</Text>
</View>
</View>
</View>
</View>
<View style={styles.card_bottom}>
<TouchableOpacity style={styles.button_accept}>
<Text style={styles.button_text}>Aceptar</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button_reject}>
<Text style={styles.button_text}>Rechazar</Text>
</TouchableOpacity>
</View>
</View>
);
};

react native onPress not working in library in android

This is the start component and below the render function onPress function works fine.
import React, { useState, useEffect, useRef } from "react"
import {
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
TextInput,
KeyboardAvoidingView,
Keyboard,
Button,
} from "react-native"
import BouncyCheckbox from "react-native-bouncy-checkbox"
import { SafeAreaView } from "react-native-safe-area-context"
import { ScrollView, TouchableWithoutFeedback } from "react-native-gesture-handler"
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"
import RNPickerSelect from "react-native-picker-select"
import Animated from "react-native-reanimated"
import BottomSheet from "reanimated-bottom-sheet"
import EventBannerSheet from "./event-banner"
export const UserInfoPhone: React.FC = () => {
const userNumberFormRef = useRef<TextInput>()
const userNumberNextFormRef = useRef<TextInput>()
const userPhoneNumberFormRef = useRef<TextInput>()
const focusToNextForm = (nextForm: any) => {
nextForm.current.focus()
}
const EssentialAgreementContainer = ({ text }) => {
return (
<View style={styles.essentialAgreementContainer}>
<View style={styles.essentialSmallBox}>
<Text style={styles.essentialAgreementText}>[필수] {text}</Text>
<TouchableOpacity style={styles.okButton}>
<Text style={styles.okButtonTitle}>보기</Text>
</TouchableOpacity>
</View>
<BouncyCheckbox
size={17}
fillColor="lightgrey"
unfillColor="lightgrey"
iconStyle={{ borderColor: "lightgrey" }}
textStyle={{ fontFamily: "JosefinSans-Regular" }}
/>
</View>
)
}
return (
<>
<SafeAreaView style={styles.container}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<KeyboardAwareScrollView>
<Image source={require("./back.png")} style={styles.backButton} />
<View style={styles.viewTitle}>
<Text style={styles.title}>휴대폰으로</Text>
<Text style={styles.title}>간편 본인인증하세요.</Text>
</View>
<View style={styles.subTitleContainer}>
<Text style={styles.subTitle}>나중에 할게요</Text>
<TouchableOpacity style={styles.okButton}>
<Text style={styles.okButtonTitle}>확인</Text>
</TouchableOpacity>
</View>
<View style={[styles.agreementContainer, styles.shadowProps]}>
<View style={styles.conditionContainer}>
<Text style={styles.agreementTitle}>본인확인 서비스에 대해 모두 동의하기</Text>
<BouncyCheckbox
size={17}
fillColor="lightgrey"
unfillColor="lightgrey"
iconStyle={{ borderColor: "lightgrey" }}
textStyle={{ fontFamily: "JosefinSans-Regular" }}
/>
</View>
<View style={styles.contour}></View>
<EssentialAgreementContainer text="서비스 이용약관 동의" />
<EssentialAgreementContainer text="통신사 이용약관 동의" />
<EssentialAgreementContainer text="개인 정보 수집 및 이용 동의" />
<EssentialAgreementContainer text="개인 제어보 제공/위탁 동의" />
<EssentialAgreementContainer text="고유식별 정보 처리" />
</View>
<View style={styles.infoForms}>
<View style={styles.nameFormContainer}>
<Text style={styles.userInfo}>성명</Text>
<TextInput
style={styles.nameForm}
onSubmitEditing={() => {
focusToNextForm(userNumberFormRef)
}}
/>
</View>
<View style={styles.personNumberFormContainer}>
<Text style={styles.userInfo}>주민등록번호 (외국인등록번호)</Text>
<View style={styles.userNumberFormContainer}>
<TextInput
style={styles.userNumberForm}
maxLength={6}
placeholder="960101"
onSubmitEditing={() => {
focusToNextForm(userNumberNextFormRef)
}}
ref={userNumberFormRef}
/>
<Text style={{ fontSize: 20 }}>-</Text>
<TextInput
style={styles.userSecondNumberForm}
maxLength={1}
ref={userNumberNextFormRef}
onSubmitEditing={() => {
focusToNextForm(userPhoneNumberFormRef)
}}
/>
</View>
</View>
<View style={styles.phoneFormContainer}>
<Text style={styles.userInfo}>휴대폰번호</Text>
<View style={styles.phoneForms}>
<View style={styles.telecome}>
<RNPickerSelect
style={{ inputAndroid: { color: "black", padding: 0, height: 20 } }}
useNativeAndroidPickerStyle={false}
onValueChange={(value) => console.log(value)}
placeholder={{ label: "통신사" }}
items={[
{ label: "SKT", value: "SKT" },
{ label: "KT", value: "KT" },
{ label: "LG U+", value: "LG U+" },
{ label: "SKT알뜰폰", value: "SKT알뜰폰" },
{ label: "KT알뜰폰", value: "KT알뜰폰" },
{ label: "LG U+알뜰폰", value: "LG U+알뜰폰" },
]}
/>
</View>
<TextInput
style={styles.phoneForm}
placeholder="010-1234-5678"
ref={userPhoneNumberFormRef}
/>
</View>
</View>
</View>
<TouchableOpacity style={styles.certificationButton}>
<Text style={styles.certificationText}>인증하기</Text>
</TouchableOpacity>
</KeyboardAwareScrollView>
</TouchableWithoutFeedback>
</SafeAreaView>
<EventBannerSheet />
</>
)
}
and this is the EventBannerSheet Component, I got this BottomSheet library and wrote it, but the onPress function doesn't work here. Also I did it before using the Checkbox library but onValueChange also didn't work in android.
import React, { useRef } from "react"
import { StyleSheet, Text, View, Image, TouchableOpacity } from "react-native"
import BottomSheet from "reanimated-bottom-sheet"
const EventBannerSheet: React.FC = () => {
const sheetRef = useRef(null)
const consoleHello = () => {
console.log("helloooooooo!!!!")
}
const renderContent = () => (
<View style={styles.bottomSheet}>
<View style={styles.sheetTextContainer}>
<Text
style={styles.sheetText}
onPress={() => {
consoleHello()
}}
>
EVENT BANNER
</Text>
<Text style={styles.sheetText}>IMG</Text>
</View>
<View style={styles.sheetCloseContainer}>
<TouchableOpacity
onPress={() => {
console.log("helloMaster123")
}}
>
<Text style={{ color: "blue" }}>오늘 하루 보지않기</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => sheetRef.current.snapTo(2)}>
<Text>닫기</Text>
</TouchableOpacity>
</View>
</View>
)
return (
<>
<BottomSheet
initialSnap={1}
ref={sheetRef}
snapPoints={[450, 350, 0]}
borderRadius={10}
renderContent={renderContent}
/>
</>
)
}
and this is stylesheet of EventBannerSheet
const styles = StyleSheet.create({
bottomSheet: {
backgroundColor: "white",
padding: 25,
height: 440,
},
sheetTextContainer: {
height: 270,
alignItems: "center",
justifyContent: "center",
backgroundColor: "#d3d3d3",
borderRadius: 10,
},
sheetText: {
fontSize: 30,
color: "white",
},
sheetCloseContainer: {
flexDirection: "row",
justifyContent: "space-between",
marginTop: 20,
},
})
<View style={styles.bottomSheet}>
<View style={styles.sheetTextContainer}>
<TouchableOpacity
style={styles.sheetText}
onPress={() => {
consoleHello()
}}
>
<Text style={{ color: "black" }}>EVENT BANNER</Text>
</TouchableOpacity>
<Text style={styles.sheetText}>IMG</Text>
</View>
<View style={styles.sheetCloseContainer}>
<TouchableOpacity
onPress={() => {
console.log("helloMaster123")
}}>
<Text style={{ color: "blue" }}>오늘 하루 보지않기</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => sheetRef.current.snapTo(2)}>
<Text>닫기</Text>
</TouchableOpacity>
</View>
</View>
Please try the above code. I have tested the code and touchable opacity is working fine without any issue. I have added a text color for EVENT BANNER text just to test. Let me know if you need any other help.
here is the config I've made to make it work on both iOS and Android with button and horizontal drag slider
<BottomSheet
initialSnap={1}
ref={sheetRef}
snapPoints={[450, 350, 0]}
borderRadius={10}
renderContent={renderContent}
enabledContentGestureInteraction={false}
enabledInnerScrolling={false}
enabledContentTapInteraction={false}
/>
I append three attributes so i solve this problem.
And the button inside the view use TouchableOpacity from RN for iOS and TouchableOpacity from react-native-gesture-handler for Android

React Native: How can I put a pop-up Modal into flatlist

I've made a flatlist with a few data inside. I want to make a pop-up information for each item in the flatlist. So I tried putting Modal into the renderItem function but when it sets the modal state visible, it will show all of the information in my flatlist. I think it should be setting the modal visible state by id or something like that but I don't know how to do it. Any suggestion?
my renderItem:
function RenderItem({ item }) {
return (
<View>
<Modal
animationType='slide'
transparent={true}
visible={infoModal}>
<View style={styles.informationContainer}>
<View style={styles.informationBox}>
<Text>{item.file.displayName}</Text>
<Button title=' OK ' onPress={() => setInfoModal(false)} />
</View>
</View>
</Modal>
<TouchableOpacity style={styles.listBox} onPress={() => setInfoModal(true)}>
<View>
<Text numberOfLines={1} style={styles.listText}>{item.file.displayName}</Text>
<Text style={{ width: 200, color: 'rgba(0, 0, 0, 0.5)' }}>{item.certificateName}</Text>
</View>
<View style={{ flexDirection: 'row', justifyContent: 'center' }}>
<TouchableOpacity>
<Icon name='search' color='black' size={25} />
</TouchableOpacity>
<Text> </Text>
<TouchableOpacity onPress={() => handleDownload(item)}>
<Icon name='download' color='black' size={25} />
</TouchableOpacity>
<Text> </Text>
</View>
</TouchableOpacity>
</View>
)
}
Instead of setting a simple boolean value about whether the Modal should appear, you can set some sort of identifiable value that tells it what item to load (and otherwise leave it undefined).
Bare-bones example:
const DATA = [
{
id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
title: 'First Item',
},
{
id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
title: 'Second Item',
},
{
id: '58694a0f-3da1-471f-bd96-145571e29d72',
title: 'Third Item',
},
];
export default function App() {
const [modalInfo, setModalInfo] = React.useState(undefined);
const renderItem = ({ item }) => (
<TouchableOpacity onPress={() => setModalInfo(item.title)}><Text>{item.title}</Text></TouchableOpacity>
);
return (
<View style={styles.container}>
<Modal visible={modalInfo !== undefined}>
<View style={[{borderWidth: 1},styles.centeredView]}>
<Text>{modalInfo}</Text>
<TouchableOpacity onPress={() => setModalInfo(undefined)}><Text>Close</Text></TouchableOpacity>
</View>
</Modal>
<FlatList
data={DATA}
renderItem={renderItem}
keyExtractor={item => item.id}
/>
</View>
);
}
const styles = StyleSheet.create({
centeredView: {
flex: 1,
justifyContent: "center",
alignItems: "center",
marginTop: 22
},
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
});

Text input becomes unusable after submitting data

I am implementing a page in my app that takes a user input and then searches a tv shows API for shows relating to what the user inputs. The form works, and data is returned succesfully, however once the search button has been clicked and the data has been returned, the search bar AND search button becomes unresponsive and will not bring up the keyboard. This was tested on a pixel 3 AVD, however on an iphone X using expo Go, the search button fully disapears from the page!
Here is the code:
import React, {useState} from 'react';
import { StyleSheet, Text, View, TextInput, TouchableOpacity, FlatList, ActivityIndicator, Image } from 'react-native';
import {AntDesign} from '#expo/vector-icons';
const ShowDisplay = ({navigation}) => {
const[text, changeText] = useState('');
const[data, setData] = useState([]);
const check = (item) => {
if(item.show.image){
return(
<Image source={{uri:item.show.image.medium}} style={{width:'100%', height: 200}} />
)
}else{
return(
<Text>Poo</Text>
)
}
}
const showfind = () =>{
fetch('https://api.tvmaze.com/search/shows?q=' + text)
.then((response)=> response.json())
.then((json)=> setData(json))
.catch((error)=>alert(error));
}
const showSearch = (text) =>{
showfind();
}
const changeHandler = (text) =>{
changeText(text)
}
console.log('text is currently '+ text)
return(
<>
<View style={styles.container}>
<View style = {styles.searchform}>
<TextInput
placeholder = 'Search for a show'
style = {styles.search}
onChangeText={text => changeHandler(text)}
/>
<TouchableOpacity onPress={() => showSearch(text)}>
<AntDesign name="search1" size={30} color='black' style = {{marginTop: 19, marginLeft: 15,}}/>
</TouchableOpacity>
</View>
</View>
<View>
{data? (<View style={styles.resultsContainer}>
<FlatList
style = {styles.list}
keyExtractor={(item, index)=> index.toString()}
numColumns= '3'
data={data}
renderItem={({item}) => (
<>
<TouchableOpacity style = {styles.show} onPress={() => navigation.navigate('toShow', {
id: item.show.id,
} )}>
<View style={styles.text}>
{check(item)}
</View>
</TouchableOpacity>
</>
)}
/>
</View>) : (<View style={styles.loadingContainer}>
<ActivityIndicator size="large" color="#000"/>
</View>)}
</View>
</>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
},
search :{
paddingLeft: 15,
marginTop: 20,
borderRadius:30,
width: 200,
height: 30,
borderWidth: 1,
borderColor: '#000'
}, header : {
marginTop: 20,
fontSize: 30,
},
searchform:{
flexDirection: 'row',
},
show:{
width: '33.3%',
height: 200,
borderStyle: "solid",
borderColor: 'white',
borderWidth: 1,
},
list:{
marginTop: 70,
}
});
export default ShowDisplay;
I thought that maybe because the sumbit button runs a function, maybe the function never stops, and needs to be reset? When the sumbit button is pressed, it makes the call to the API.. I am unsure what is happening.
Looks like you're getting a weird side effect by using a Fragment (<></>) as the root view. The style is getting thrown off in certain circumstances.
Since you don't actually have a reason to use a Fragment as the root (your container view is the root element), removing it seemed to solve the issue. I also removed the unnecessary fragment you were using in the search button.
return(
<View style={styles.container}>
<View style = {styles.searchform}>
<TextInput
placeholder = 'Search for a show'
style = {styles.search}
onChangeText={text => changeHandler(text)}
/>
<TouchableOpacity onPress={() => showSearch(text)}>
<AntDesign name="search1" size={30} color='black' style = {{marginTop: 19, marginLeft: 15,}}/>
</TouchableOpacity>
</View>
<View>
{data? (<View style={styles.resultsContainer}>
<FlatList
style = {styles.list}
keyExtractor={(item, index)=> index.toString()}
numColumns= '3'
data={data}
renderItem={({item}) => (
<TouchableOpacity style = {styles.show} onPress={() =>
navigation.navigate('toShow', {
id: item.show.id,
} )}>
<View style={styles.text}>
{check(item)}
</View>
</TouchableOpacity>
)}
/>
</View>) : (<View style={styles.loadingContainer}>
<ActivityIndicator size="large" color="#000"/>
</View>)}
</View>
</View>
);

undefined is not a function(evaluating '_this2.AlertButton()')?

I create touchableopacity for every item in map. it works well but when I give function to TouchableOpacity like below, it gives me error which is on title. How can I fix this ?
it gives error when I write this.AlertButton()
{section.subcategory.map((item, key) => (
<View key={key} style={styles.item}>
<TouchableOpacity
onPress={() =>this.AlertButton()}>
</TouchableOpacity>
<View style={styles.separator} />
</View>
))}
This is my alert function :
AlertButton() {
const number = 'TelNo';
Alert.alert(
'',
'Test',
[
{text: 'NO'},
{text: 'Yes', onPress: () => Linking.openURL(`tel:${number}`)},
],
);
}
Here is render. And my map function which is above is in renderContent
render() {
CONTENT2 =[];
CONTENT2 = this.state.fromPage1;
return (
<View style={styles.container}>
<View style={{height: this.state.yuksek, width: this.state.genis, justifyContent: 'center', alignItems: 'center',position:'absolute'}}>
<Text style={{fontWeight: 'bold', color:'#856F6F'}}>Yukarıdaki menü butonlarına tıklayınız.</Text>
</View>
<View style={{height: this.state.yuksek2, width: this.state.genis2, justifyContent: 'center', alignItems: 'center'}}>
<Text style={{fontWeight: 'bold', color:'#856F6F'}}>String</Text>
</View>
<ScrollView contentContainerStyle={{}}>
<Accordion
activeSections={this.state.activeSections}
sections={CONTENT2}
touchableComponent={TouchableOpacity}
expandMultiple={false}
renderHeader={this.renderHeader}
renderContent={this.renderContent}
duration={400}
onChange={this.setSections}
/>
</ScrollView>
<View style={{height:85, width:85,position:'absolute',bottom:5,right:5}}>
<TouchableOpacity style={{flex:1}} onPress={() => this.AlertButton()}>
<ImageBackground source={require('../../image/phoneCall.png')} style={{flex:1}}>
</ImageBackground>
</TouchableOpacity>
</View>
</View>
);
}
}
just change the following line
renderContent={this.renderContent}
to
renderContent={this.renderContent.bind(this)}
because when you are using the class method directly as callback then its not definitely bound to its class when called from inside the component