react-native-side-menu Out of phase - react-native

I am working whit react-native-side-menu, but I have a problem whith the menu that I want to display, in fact when I put the menu property this element is showing all the time also when isOpen is set as false. This is my Code:
import React, {Component} from 'react';
import {Dimensions,ListView,ScrollView,StatusBar,Text,TouchableOpacity,View} from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';
import {Colors as JoboColors} from '../styles/General';
import SideMenu from 'react-native-side-menu';
//import SideBar from './SideBar';
export default class JobList extends Component {
state = {
isOpen: false,
};
handleMenu = () => {
this.setState({isOpen: !this.state.isOpen});
}
updateMenuState = (isOpen) => {
this.setState({ isOpen});
}
render() {
const myMenu = <UserMenu />;
return (
<SideMenu menu={myMenu}
isOpen={this.state.isOpen}
onChange={this.updateMenuState}>
<View>
<StatusBar
backgroundColor= {JoboColors.orangeC}
barStyle="light-content"
translucent={false}/>
<View style={styles.actionBar}>
<TouchableOpacity style={styles.menuIcon} onPress={this.handleMenu}>
<Icon name="ios-menu" size={32} style={styles.actionBarIcons}/>
</TouchableOpacity>
<Icon name="ios-search" size={30} style={styles.actionBarIcons}/>
</View>
<View style={{backgroundColor: 'white', justifyContent: 'center', flex: 1}}>
<Text>This is the content</Text>
</View>
</View>
</SideMenu>
);
}
}
class UserMenu extends Component {
render() {
return(
<ScrollView style={styles.content}>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
actionBar: {
height: 50,
flexDirection: 'row',
backgroundColor: Colors.orangeA,
alignItems: "center",
padding: 15,
},
actionBarIcons: {
color: "white",
},
menuIcon: {
flex: 2,
},
content: {
backgroundColor: 'blue',
},
});
And this is the view result, please notice that the blue block is the view for the slide-menu. Somebody has a similar problem like this?
Thanks in advance.

Simplified version of answer -
render() {
const myMenu = <UserMenu />;
return (
<View style={{flex:1}}>
<StatusBar backgroundColor="orange" barStyle="light-content" translucent={false}/>
<View style={styles.actionBar}>
<TouchableOpacity style={styles.menuIcon} onPress={this.handleMenu}>
<Text style={styles.actionBarIcons}>menu</Text>
</TouchableOpacity>
<Text style={styles.actionBarIcons}>search</Text>
</View>
<View style={{flex:1}}>
<SideMenu menu={myMenu} isOpen={this.state.isOpen} onChange={this.updateMenuState}>
<View style={{backgroundColor: 'white', justifyContent: 'center', flex: 1}}>
<Text>This is the content</Text>
</View>
</SideMenu>
</View>
</View>
);
}

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'
}
});

Invalid hook call hooks can only be called inside of the body of a function component

I am currently implementing a modal using the Modalize library. I'm using Hooks for the requests but as soon as I'm going to call the Modalize component it returns the following error. I've spent a lot of time and haven't figured out where the problem is
import React, { useRef } from 'react';
import { Modalize } from 'react-native-modalize';
export default class MyScreen extends React.Component {
render() {
const modalizeRef = useRef(null);
function onOpen() {
modalizeRef.current?.open();
}
return (
<View>
<TouchableOpacity onPress={onOpen}>
<Text>click me</Text>
</TouchableOpacity>
<Modalize
ref={modalizeRef}
snapPoint={180}
>
<View
style={{
flex: 1,
height: 100,
flexDirection: 'row',
}}>
<TouchableOpacity style={[style.btnTest, { backgroundColor: '#29ae19' }]}>
Button 01
</TouchableOpacity>
<TouchableOpacity style={[style.btnTest, { backgroundColor: '#ff0000' }]}>
Button 02
</TouchableOpacity>
</View>
</Modalize>
</View>
);
}
}
You're only supposed to use hooks in functional components.
Read the docs here
export default function MyScreen() {
const modalizeRef = useRef(null);
function onOpen() {
modalizeRef.current?.open();
}
return (
<View>
<TouchableOpacity onPress={onOpen}>
<Text>click me</Text>
</TouchableOpacity>
<Modalize
ref={modalizeRef}
snapPoint={180}
>
<View
style={{
flex: 1,
height: 100,
flexDirection: 'row',
}}>
<TouchableOpacity style={[style.btnTest, { backgroundColor: '#29ae19' }]}>
Button 01
</TouchableOpacity>
<TouchableOpacity style={[style.btnTest, { backgroundColor: '#ff0000' }]}>
Button 02
</TouchableOpacity>
</View>
</Modalize>
</View>
);
}
From what I can gather you want a ref.
there are 2 ways
declare it in constructor using createRef(no import needed)
constructor(props){
this.modalizeRef = React.createRef();
}
assign it in the component call
<Modalize
ref={(ref) => {
this.modalizeRef = ref;
}}
/>
I managed to solve it by doing this using the refs callback
export default class MyScreen extends React.Component {
constructor(props) {
super(props);
this.modalizeRef = React.createRef();
}
onOpen() {
this.modalizeRef.current?.open();
}
}
<View>
<TouchableOpacity onPress={this.onOpen.bind(this)}>
<Text>click me</Text>
</TouchableOpacity>
<Modalize
ref={this.modalizeRef}
snapPoint={180}
>
<View
style={{
flex: 1,
height: 100,
flexDirection: 'row',
}}>
<TouchableOpacity style={[style.btnTest, { backgroundColor: '#29ae19' }]}>
Button 01
</TouchableOpacity>
<TouchableOpacity style={[style.btnTest, { backgroundColor: '#ff0000' }]}>
Button 02
</TouchableOpacity>
</View>
</Modalize>
</View>

react-native position element at the bottom

I am trying to move a react native component called "forum" to the bottom of the screen, I tried position: fixed, bottom:0 but it didn't work
I also tried 'flex-end' and still didn't work
any idea what's wrong?
here is the expo code:
import React from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import { DrawerNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('DrawerOpen')}>
<Text>Open Drawer</Text>
</TouchableOpacity>
<Text style={{ fontWeight: 'bold', marginTop: 20 }}>Home</Text>
</View>
);
}
}
class Enquiry extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('DrawerOpen')}>
<Text>Open Drawer</Text>
</TouchableOpacity>
<Text style={{ fontWeight: 'bold', marginTop: 20 }}>Enquiry</Text>
</View>
);
}
}
class Batches extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('DrawerOpen')}>
<Text>Open Drawer</Text>
</TouchableOpacity>
<Text style={{ fontWeight: 'bold', marginTop: 20 }}>Batches</Text>
</View>
);
}
}
class Forum extends React.Component {
render() {
return (
<View style={{ flex:1,justifyContent:'center',alignItems: 'center',position:'absolute',bottom:0}}>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('DrawerOpen')}>
<Text>Open Drawer</Text>
</TouchableOpacity>
<Text style={{ fontWeight: 'bold',marginBottom:36}}>Forum</Text>
</View>
);
}
}
const MyDrawerNavigator = new DrawerNavigator(
{
Home: HomeScreen,
Batches:Batches,
Enquiry:Enquiry,
Forum:Forum,
},
{
drawerBackgroundColor: 'rgba(255,255,255,.9)',
contentOptions: {
activeTintColor: '#fff',
activeBackgroundColor: '#6b52ae',
},
}
);
export default MyDrawerNavigator;
I am not allowed to share images but click the link to see
enter image description here
The valid position option in react native is relative or absolute. The default value is relative.
If you want scroll content and fix position of Forum in your screen, you have to separate your view hierarchy like the following and use absolute position.
<View>
<ScrollView>
...anything content
</ScrollView>
<Forum style={{position:'absolute', bottom: 0}}/>
</View>
<...>
<MyDrawerNavigator .../>
<Forum style={{position:'absolute', bottom: 0}} .../>
<.../>

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'
}
});