how to fix RNSVGGroup error in react native expo app? - react-native

I'm new to react native and following the tutorial on youtube. After setup sanity for the backend app gave an error. This is the tutorial:- https://youtu.be/AkEnidfZnCU
this is my code:
import { useNavigation } from '#react-navigation/native';
import React, { useEffect, useLayoutEffect, useState } from 'react';
import { View, Text, Image, TextInput, ScrollView } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { UserIcon, ChevronDownIcon, MagnifyingGlassIcon, AdjustmentsHorizontalIcon } from "react-native-heroicons/outline";
import Categories from '../components/Categories';
import FeaturedRow from '../components/FeaturedRow';
import client from '../sanity';
const HomeScreen = () => {
const navigation = useNavigation();
const [featuredCategories, setFaaturedCategories] = useState([]);
useLayoutEffect(() => {
navigation.setOptions({
headerShown: false,
})
}, []);
useEffect(() => {
client.fetch(`
*[_type =="featured"]{
...,
restaurants[]->{
...,
dishes[]->
}
}
`).then(data => {
setFaaturedCategories(data);
});
}, []);
return (
<SafeAreaView className="bg-white pt-5">
{/* Header */}
<View className="flex-row pb-3 items-center mx-4 space-x-2">
<Image
source={{
uri: 'https://links.papareact.com/wru',
}}
className="h-7 w-7 bg-gray-300 p-4 rounded-full"
/>
<View className="flex-1">
<Text className="font-bold text-gray-400 text-xs">Deliver Now!</Text>
<Text className="font-bold text-xl">Current Location
<ChevronDownIcon size={20} color="#00CCBB" />
</Text>
</View>
<UserIcon size={35} color="#00CCBB" />
</View>
{/* Search box */}
<View className="flex-row items-center space-x-2 pb-2 mx-4">
<View className="flex-row flex-1 space-x-2 bg-gray-200 p-3">
<MagnifyingGlassIcon size={20} color="gray" />
<TextInput placeholder='Restaurant and cuisines' keyboardType='default' />
</View>
<AdjustmentsHorizontalIcon color="#00CCBB" />
</View>
{/* Body */}
<ScrollView className="bg-gray-100" contentContainerStyle={{ paddingBottom: 100 }}>
{/* Categories */}
<Categories />
{/* Featured Rows */}
<FeaturedRow
id="123"
title="Featured"
description="paid placemnts from our partners"
/>
{/* Tasty Discount */}
<FeaturedRow
id="1234"
title="Tasty Discount"
description="Everyone's been enjoying these juicy Discount"
/>
{/* Offers near you */}
<FeaturedRow
id="12345"
title="Offers near you"
description="Why not support your local restaurant tonight!"
/>
</ScrollView>
</SafeAreaView>
);
}
export default HomeScreen;
I have followed all the steps from the video. But it gives me an error.
This is sanity.js file
import sanityClient from '#sanity/client'
import imageUrlBuilder from '#sanity/image-url'
const client = sanityClient({
projectId: "gbg977pk",
dataset: "production",
useCdn: true,
apiVersion: "2021-10-21",
});
const builder = imageUrlBuilder(client);
export const urlFor = (source) => builder.image(source);
export default client;
This is the error
Please help me to solve this problem.

In React Native, you should use the style attribute to apply CSS styles to your elements, rather than the className attribute.
Consider for example, the line:
<SafeAreaView className="bg-white pt-5">
It should be changed to:
<SafeAreaView style={{ backgroundColor: 'white', paddingTop: 5 }}>
Your code with the changes applied:
import { useNavigation } from '#react-navigation/native';
import React, { useEffect, useLayoutEffect, useState } from 'react';
import { View, Text, Image, TextInput, ScrollView } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { UserIcon, ChevronDownIcon, MagnifyingGlassIcon, AdjustmentsHorizontalIcon } from "react-native-heroicons/outline";
import Categories from '../components/Categories';
import FeaturedRow from '../components/FeaturedRow';
import client from '../sanity';
const HomeScreen = () => {
const navigation = useNavigation();
const [featuredCategories, setFaaturedCategories] = useState([]);
useLayoutEffect(() => {
navigation.setOptions({
headerShown: false,
})
}, []);
useEffect(() => {
client.fetch(`
*[_type =="featured"]{
...,
restaurants[]->{
...,
dishes[]->
}
}
`).then(data => {
setFaaturedCategories(data);
});
}, []);
return (
<SafeAreaView style={{ backgroundColor: 'white', paddingTop: 5 }}>
{/* Header */}
<View style={{ flexDirection: 'row', paddingBottom: 3, marginHorizontal: 4, alignItems: 'center', justifyContent: 'space-between' }}>
<Image
source={{
uri: 'https://links.papareact.com/wru',
}}
style={{ height: 7, width: 7, backgroundColor: 'gray-300', padding: 4, borderRadius: 'full' }}
/>
<View style={{ flex: 1 }}>
<Text style={{ fontWeight: 'bold', color: 'gray-400', fontSize: 'xs' }}>Deliver Now!</Text>
<Text style={{ fontWeight: 'bold', fontSize: 'xl' }}>Current Location
<ChevronDownIcon size={20} color="#00CCBB" />
</Text>
</View>
<UserIcon size={35} color="#00CCBB" />
</View>
{/* Search box */}
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingBottom: 2, marginHorizontal: 4 }}>
<View style={{ flexDirection: 'row', flex: 1, justifyContent: 'space-between', backgroundColor: 'gray-200', padding: 3 }}>
<MagnifyingGlassIcon size={20} color="gray" />
<TextInput placeholder='Restaurant and cuisines' keyboardType='default' />
</View>
<AdjustmentsHorizontalIcon color="#00CCBB" />
</View>
{/* Body */}
<ScrollView style={{ backgroundColor: 'gray-100' }} contentContainerStyle={{ paddingBottom: 100 }}>
{/* Categories */}
<Categories />
{/* Featured Rows */}
<FeaturedRow
id="123"
title="Featured"
description="paid placemnts from our partners"
/>
{/* Tasty Discount */}
<FeaturedRow
id="1234"
title="Tasty Discount"
description="Everyone's been enjoying these juicy Discount"
/>
{/* Offers near you */}
<FeaturedRow
id="12345"
title="Offers near you"
description="Why not support your local restaurant tonight!"
/>
</ScrollView>
</SafeAreaView>
);
}
export default HomeScreen;

Related

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

Can't see buttons neither my textinputs get inputs in my react native expo app

I am building a login screen. i am totally fresh in it. I took google help to get my 3 buttons in a single row using grid view. This is my code:
import { StatusBar } from 'expo-status-bar';
import React, {useState,useEffect, Component} from "react";
import { StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native';
export class GridView extends Component {
render() {
return (
<View style={styles.container}>
<View style={styles.buttonContainer}>
<Button title="Button 1"/>
</View>
<View style={styles.buttonContainer}>
<Button title="Button 2"/>
</View>
<View>
<TouchableOpacity>
<Text style={style.Email_btn}>
Email
</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
export default function App() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
return (
<View style={styles.container}>
<Text style={{color:'#ffffff', fontSize:28}}>LOG IN</Text>
<StatusBar style="auto" />
<View style={styles.inputView}>
<TextInput
style={styles.TextInput}
autoCapitalize="none"
placeholder="Email."
placeholderTextColor="#003f5c"
onChangeText={(email) => setEmail(email)}
/>
</View>
<View style={styles.inputView}>
<TextInput
style={styles.TextInput}
placeholder="Password."
placeholderTextColor="#003f5c"
secureTextEntry={true}
onChangeText={(password) => setPassword(password)}
/>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
buttonContainer: {
flex: 1,
},
Email_btn:{
backgroundColor:"#1c313a",
width:30,
height:80,
},
container: {
flex: 2,
backgroundColor: '#455a64',
/*alignItems:'flex-start',
justifyContent: 'center'*/
},
inputView: {
backgroundColor: '#1c313a',
borderRadius: 30,
width: "70%",
height: 45,
marginBottom: 20,
alignItems: "center",
},
TextInput: {
height: 50,
flex: 1,
padding: 10,
marginLeft: 20,
}
});
The buttons in the grid view class should appear in the same row. below them there should be the email and password textinputs. I can't see the buttons on my screen neither my textinputs are getting the texts from users. Kindly help me!!
you added flexDirection:'row' to your app container View. that means everything you add inside it, will be displayed horizontal.
also you are not rendering <GridView Class component in App.
you need to cross check your styles which effects most of the layout.
here is the modified snippet for you.
import React, {useState, Component} from "react";
import { StatusBar, Button, StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native';
export class GridView extends Component {
render() {
return (
<View style={styles.btnContainer}>
<View style={styles.button}>
<Button color={'white'} title="Button 1"/>
</View>
<View style={styles.button}>
<Button color={'white'} title="Button 2"/>
</View>
<View style={[styles.button, styles.emailBtnWrap]}>
<TouchableOpacity>
<Text style={styles.emailBtn}>
Email
</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
export default function App() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
return (
<View style={styles.containerWrap}>
<StatusBar />
<View style={styles.textCenter}>
<Text style={styles.textColor}>LOG IN</Text>
</View>
<View style={styles.formContainer}>
<View style={styles.inputView}>
<TextInput
autoCapitalize="none"
placeholder="Email."
placeholderTextColor="#003f5c"
onChangeText={(email) => setEmail(email)}
/>
</View>
<View style={styles.spacing12} />
<View style={styles.inputView}>
<TextInput
placeholder="Password."
placeholderTextColor="#003f5c"
secureTextEntry={true}
onChangeText={(password) => setPassword(password)}
/>
</View>
</View>
<GridView />
</View>
);
}
const styles = StyleSheet.create({
containerWrap: {
flex: 1,
},
textCenter: {
flex:1,
alignItems: 'center',
justifyContent: 'center'
},
textColor: {
color:'#000',
fontSize:28
},
formContainer: {
flex:1,
padding:12
},
inputView: {
backgroundColor: '#f9f9f9',
borderRadius: 30,
borderWidth:1,
borderColor: '#ccc',
paddingVertical:16,
paddingHorizontal:12
},
spacing12: {
marginVertical:12
},
btnContainer: {
flexDirection: 'row'
},
button: {
flex:1,
backgroundColor:'blue',
padding:12
},
emailBtnWrap: {
backgroundColor:'green'
},
emailBtn: {
color:'white'
},
btnColor: {
color:'white'
}
});

KeyboardAvoidingView doesn't work properly on my app

I searched a lot about this issue and I don't know what to do now so I decided to ask here and any help would be appreciated. in my register screen I have some input that user must fill and for the last one I need to avoid keyboard overlay. so I used KeyboardAvoidingView component to solve this but as you can see in the screenshot the device keyboard still overlay my input (birth date).
here is my code for this screen :
import React, { useState } from 'react';
import { View, Text, KeyboardAvoidingView, Image, Dimensions, PixelRatio, StyleSheet } from 'react-native';
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen';
import { COLORS } from '../Constants/COLORS';
import PrimaryButton from '../Components/PrimaryButton';
import PrimaryInput from '../Components/PrimaryInput';
import CheckBox from '../Components/CheckBox';
const Register = (props) => {
const [lisenceTerm, setLisenceTerm] = useState(true);
const [privacyPolicy, setPrivacyPolicy] = useState(true);
return (
<View style={styles.screen}>
<View style={styles.imageContainer}>
<Image style={styles.image} source={require('../assets/Img/office_5.jpg')} />
</View>
<View style={styles.loginContainer}>
<View style={styles.headerContainer}>
<Text style={styles.headerText}>Join us</Text>
</View>
<KeyboardAvoidingView style={styles.inputContainer}>
<PrimaryInput placeholder='Name Surname' />
<PrimaryInput placeholder='Your Email' />
<PrimaryInput placeholder='Phone Number (05***)' />
<PrimaryInput placeholder='Birth Date' />
</KeyboardAvoidingView>
<View style={styles.checkBoxContainer}>
<CheckBox text='Kvkk sözleşmesini okudum, kabul ediyorum' active={lisenceTerm} onPress={() => setLisenceTerm(!lisenceTerm)} />
<CheckBox text='Kullanıcı sözleşmesini okudum, kabul ediyorum' active={privacyPolicy} onPress={() => setPrivacyPolicy(!privacyPolicy)} />
</View>
<View style={styles.buttonsContainer}>
<PrimaryButton
buttonStyle={styles.button}
textStyle={styles.buttonText}
title='Register' />
</View>
</View>
</View>
)
}
const styles = StyleSheet.create({
screen: {
flex: 1,
},
imageContainer: {
width: '100%',
height: '34%'
},
image: {
width: '100%',
height: '100%'
},
loginContainer: {
backgroundColor: 'white',
width: '100%',
height: '71%',
position: 'absolute',
zIndex: 1,
bottom: 0,
borderTopLeftRadius: 40,
borderTopRightRadius: 40,
alignItems: 'center'
},
buttonsContainer: {
width: '100%',
justifyContent: 'center',
alignItems: 'center'
},
button: {
justifyContent: 'center',
alignItems: 'center',
width: '75%',
paddingVertical: '3%',
marginTop: hp(1.2),
borderRadius: hp(3.5),
backgroundColor: COLORS.royalBlue
},
buttonText: {
fontSize: hp(3.2),
fontFamily: 'BalooPaaji2ExtraBold',
color: 'white'
},
arrow: {
right: 20
},
inputContainer: {
width: '100%',
justifyContent: 'center',
alignItems: 'center',
marginBottom: hp(1),
},
headerContainer: {
marginTop: hp(3),
marginBottom: hp(2),
width: '75%',
},
headerText: {
fontSize: hp(3.5),
fontFamily: 'BalooPaaji2Bold',
color: COLORS.royalBlue
},
checkBoxContainer: {
width: '70%',
justifyContent: 'flex-start',
marginBottom: hp(1)
}
})
export default Register;
and here below is the result. btw I used behavior and keyboardVerticalOffset props to control the way this component behave but still same problem.
Your KeyboardAvoidingView component must be on top of render tree
In order to scroll onto your Join us view, you must set a ScrollView in your KeyboardAvoidingView and those component must be on top of renderer.
Try this (based on my iOS / android setup) :
import { KeyboardAvoidingView, ScrollView } from 'react-native';
const Register = (props) => {
const [lisenceTerm, setLisenceTerm] = useState(true);
const [privacyPolicy, setPrivacyPolicy] = useState(true);
return (
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={(Platform.OS === 'ios') ? 'padding' : null}
enabled
keyboardVerticalOffset={Platform.select({ ios: 80, android: 500 })}>
<ScrollView>
<View style={styles.screen}>
<View style={styles.imageContainer}>
<Image style={styles.image} source={require('../assets/Img/office_5.jpg')} />
</View>
<View style={styles.loginContainer}>
<View style={styles.headerContainer}>
<Text style={styles.headerText}>Join us</Text>
</View>
<View style={styles.inputContainer}>
<PrimaryInput placeholder='Name Surname' />
<PrimaryInput placeholder='Your Email' />
<PrimaryInput placeholder='Phone Number (05***)' />
<PrimaryInput placeholder='Birth Date' />
</View>
<View style={styles.checkBoxContainer}>
<CheckBox text='Kvkk sözleşmesini okudum, kabul ediyorum' active={lisenceTerm} onPress={() => setLisenceTerm(!lisenceTerm)} />
<CheckBox text='Kullanıcı sözleşmesini okudum, kabul ediyorum' active={privacyPolicy} onPress={() => setPrivacyPolicy(!privacyPolicy)} />
</View>
<View style={styles.buttonsContainer}>
<PrimaryButton
buttonStyle={styles.button}
textStyle={styles.buttonText}
title='Register' />
</View>
</View>
</View>
</ScrollView>
</KeyboardAvoidingView>
)
}
you need to install react-native-keyboard-aware-scroll-view by
yarn add react-native-keyboard-aware-scroll-view
and you need to wrap KeyboardAwareScrollView instead of KeyboardAvoidingView
like
import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view';
<KeyboardAwareScrollView>
<View>
...
</View
</KeyboardAwareScrollView>
import { useHeaderHeight } from "#react-navigation/elements"
import {
Keyboard,
Platform,
TouchableWithoutFeedback,
View,
KeyboardAvoidingView
} from "react-native"
const Chat = () => {
// This is the crucial variable we will place it in
// KeyboardAvoidingView -> keyboardVerticalOffset
const headerHeight = useHeaderHeight()
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<KeyboardAvoidingView
style={{ position: "absolute", bottom: 0, left: 0, right: 0 }}
behavior={Platform.OS === "ios" ? "padding" : "height"}
// If you want the input not to stick exactly to the keyboard
// add a const here for example headerHeight + 20
keyboardVerticalOffset={headerHeight}
>
<View style={{ flex: 1, justifyContent: "flex-end" }}>
<InputWrapper>
<RawInput />
</InputWrapper>
</View>
</KeyboardAvoidingView>
</TouchableWithoutFeedback>
)
}
Also take a look at this article it might be helpful: https://medium.com/#nickyang0501/keyboardavoidingview-not-working-properly-c413c0a200d4

Drawer component in native-base shows the error 'Warning: Function components cannot be...'

I'm developing a new mobile app with Drawer component in native-base.
And I'm facing the error message below when clicking the Icon on the right side on the header.
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRed()?
This is the GIF when clicking the icon.
https://gyazo.com/31c6483acfda7ad3c6239e6171dbe688
These are my code.
App.js
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import { createDrawerNavigator,createAppContainer, createStackNavigator, DrawerItems } from 'react-navigation'
import { Container, Content, Header, Left } from 'native-base';
import { Router, Scene } from 'react-native-router-flux';
import HomeScreen from './src/screens/HomeScreen';
import NoticeScreen from './src/screens/NoticeScreen';
import UserScreen from './src/screens/UserScreen';
export default class App extends Component{
render(){
return(
<Router>
<Scene key='root'>
<Scene key='HomeScreen' component={HomeScreen} hideNavBar={true} panHandlers={null}/>
<Scene key='NoticeScreen' component={NoticeScreen} hideNavBar={true} panHandlers={null} />
<Scene key='UserScreen' component={UserScreen} hideNavBar={true} panHandlers={null} />
</Scene>
</Router>
);
}
}
HomeScreen.js
import React, { Component } from 'react';
import { Image, ImageBackground, Text, Linking, ScrollView, StyleSheet, View, Dimensions, TouchableOpacity, SafeAreaView } from 'react-native';
import { Body, Container, Content, ListItem, List, Header, Icon, Left, Right, Thumbnail, Drawer } from "native-base";
import { Actions } from 'react-native-router-flux';
import SidebarContainer from '../containers/SidebarContainer';
export default class HomeScreen extends Component {
openDrawer() {
this.drawer._root.open();
};
closeDrawer() {
this.drawer._root.close();
};
render() {
return (
<Drawer
ref={(ref) => { this.drawer = ref; }}
content={<SidebarContainer navigator={this._navigator} />}
openDrawerOffset={0.4}
tapToClose={true}
onClose={() => this.closeDrawer}
onOpen={() => this.openDrawer}
styles={{ height: 100 }}
>
<ImageBackground source={require('../../assets/header/blue.jpg')} style={{ width: null }}>
<Header style={{ backgroundColor: 'transparent' }}>
<Left style={{ flexDirection: 'row'}}>
<Icon onPress={this.openDrawer.bind(this)} type='MaterialIcons' name='menu' style={{ color: 'white', justifyContent: 'center' }} />
</Left>
<Body>
</Body>
<Right>
<TouchableOpacity onPress={Actions.UserScreen}>
<Thumbnail small source={require('../../assets/thumbnail.png')} style={{ justifyContent: 'center' }} />
</TouchableOpacity>
</Right>
</Header>
</ImageBackground>
</Drawer>
)
}
}
UserScreen.js
import React, { Component } from 'react';
import { Image, ImageBackground, Text, ScrollView, View } from 'react-native';
import { Body, Header, Icon, Left, Right, Thumbnail, Card, CardItem } from "native-base";
import { Drawer } from 'react-native-router-flux';
import SidebarContainer from '../containers/SidebarContainer';
import SmallHeadLineComponent from '../components/SmallHeadLineComponent';
export default class UserScreen extends Component {
openDrawer() {
this.drawer._root.open();
};
closeDrawer() {
this.drawer._root.close();
};
render() {
return (
<Drawer
ref={(ref) => { this.drawer = ref; }}
content={<SidebarContainer navigator={this._navigator} />}
openDrawerOffset={0.4}
tapToClose={true}
onClose={() => this.closeDrawer}
onOpen={() => this.openDrawer}
styles={{ height: 100 }}
>
<ImageBackground source={require('../../assets/header/blue.jpg')} style={{ width: null }}>
<Header style={{ backgroundColor: 'transparent' }}>
<Left style={{ flexDirection: 'row'}}>
<Icon onPress={this.openDrawer.bind(this)} type='MaterialIcons' name='menu' style={{ color: 'white', justifyContent: 'center' }} />
</Left>
<Body>
</Body>
<Right>
<Icon onPress={() => (alert('Open Modal'))} type='MaterialIcons' name='mail' style={{ color: 'white', justifyContent: 'center' }} />
</Right>
</Header>
</ImageBackground>
<ScrollView style={{ paddingTop: 10 }}>
<View style={{ flex:1, justifyContent: 'center', alignItems: 'center', marginTop: 10 }}>
<Thumbnail large source={require('../../assets/thumbnail.png')} style={{ justifyContent: 'center' }}/>
</View>
<View>
<Card style={{ marginLeft: 100, width: 200, justifyContent: 'center' }}>
<CardItem style={{ alignItems: 'center' }}>
<Body>
<Text style={{ fontWeight: 'bold', alignItems: 'center', justifyContent: 'center' }}>
kikuchi.user
</Text>
</Body>
</CardItem>
</Card>
</View>
<View>
<SmallHeadLineComponent text={'Sample'} />
</View>
</ScrollView>
</Drawer>
)
}
}
SidebarCotainer.js
import React, { Component } from 'react';
import { View, Text, ImageBackground, Image, TouchableOpacity, SafeAreaView } from 'react-native';
import { Container, Content, Drawer, Header, Left, Icon, Body, Right, Thumbnail, List, ListItem } from 'native-base';
import { Actions } from 'react-native-router-flux';
export default class SidebarContainer extends Component {
render() {
return (
<Container>
<View style={{ height: 1000 }}>
<Header style={{ height: 65, backgroundColor: 'white' }}>
<Left>
<Text style={{ paddingLeft: 10 }}>
Sidebar Title
</Text>
</Left>
</Header>
<Content>
<List>
<ListItem button noBorder={true} onPress={Actions.HomeScreen} >
<Icon type='Ionicons' name='md-home' />
<Text style={{ paddingLeft: 10 }}>Home</Text>
</ListItem>
<ListItem button noBorder={true} onPress={Actions.NoticeScreen} >
<Icon type='Ionicons' name='ios-notifications' />
<Text style={{ paddingLeft: 10 }}>Notice</Text>
</ListItem>
<ListItem button onPress={Actions.SignInScreen} >
<Icon type='Ionicons' name='ios-remove-circle-outline' />
<Text style={{ paddingLeft: 10 }}>SignOut</Text>
</ListItem>
</List>
</Content>
</View>
</Container>
)
}
}
I understand why I'm wrong.
I'm using Drawer component from react-native-router-flux. I thought I'm using the one from native-base.
I don't have to rely on the code completion in my IDE.

Two buttons with equal width horizontally fill the screen in React Native

I need to create two or more buttons which will be of equal width and horizontally aligned, based on screen width button width may vary.
You can wrap you Buttons into flexed Views :
import React, { Component } from 'react';
import { Button, View, StyleSheet } from 'react-native';
export default const FlexedButtons () => (
<View style={styles.container}>
<View style={styles.buttonContainer}>
<Button title="Button 1"/>
</View>
<View style={styles.buttonContainer}>
<Button title="Button 2"/>
</View>
</View>
);
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
buttonContainer: {
flex: 1,
}
});
Here is a working example on Sketch:
https://snack.expo.io/SyMpPSise
import React, { Component } from 'react';
import { Button, StyleSheet, View } from 'react-native';
export default class ButtonExample extends Component {
_onPressButton() {
alert('You tapped the button!')
}
render() {
return (
<View style={styles.container}>
<View style={styles.buttonContainer}>
<Button
onPress={this._onPressButton}
title="Press Me"
/>
</View>
<View style={styles.buttonContainer}>
<Button
onPress={this._onPressButton}
title="Press Me"
color="#841584"
/>
</View>
<View style={styles.alternativeLayoutButtonContainer}>
<Button
onPress={this._onPressButton}
title="This looks great!"
/>
<Button
onPress={this._onPressButton}
title="OK!"
color="#841584"
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
buttonContainer: {
margin: 20
},
alternativeLayoutButtonContainer: {
margin: 20,
flexDirection: 'row',
justifyContent: 'space-between'
}
});
<View style={styles.menuContainer}>
<TouchableOpacity onPress={() => this.pressLink('Home')}>
<View style={styles.imageTextContainer}>
<Image
source={require('./on.png')} />
<Text style={{flex:1 ,color: '#fff',fontSize: 20,marginLeft: 20}} >Home</Text>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.pressLink('About')}>
<View style={styles.imageTextContainer}>
<Image
source={require('./on.png')} />
<Text style={{flex:1 ,color: '#fff',fontSize: 20,marginLeft: 20}} >About</Text>
</View>
</TouchableOpacity>
</View>
const styles = StyleSheet.create({
menuContainer: {
flex: 0.52,
marginLeft: 5
},
imageTextContainer: {
marginLeft: 20,
padding: 10,
flexDirection: 'row',
justifyContent: 'space-between'
}
});