Javascript react native:手风琴列表在我的设备中不起作用,但在网络中起作用
我尝试在我的设备中运行此代码时遇到了一些问题,因为它不是在运行,而是在网络中运行。。 我真的不知道那里有什么问题,怎么解决。 我扫描了expo客户端的二维码,但我什么也没看到,但仍然看到它在网络快餐中起作用,正如你所看到的。 我必须设法解决这个问题,因为它太重要了。 必须说,我的项目是没有世博会的,也许这就是问题所在?如果是,我如何修复它 App.jsJavascript react native:手风琴列表在我的设备中不起作用,但在网络中起作用,javascript,reactjs,react-native,react-hooks,Javascript,Reactjs,React Native,React Hooks,我尝试在我的设备中运行此代码时遇到了一些问题,因为它不是在运行,而是在网络中运行。。 我真的不知道那里有什么问题,怎么解决。 我扫描了expo客户端的二维码,但我什么也没看到,但仍然看到它在网络快餐中起作用,正如你所看到的。 我必须设法解决这个问题,因为它太重要了。 必须说,我的项目是没有世博会的,也许这就是问题所在?如果是,我如何修复它 App.js import * as React from 'react'; import { SafeAreaView, Text, View, Styl
import * as React from 'react';
import { SafeAreaView, Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
import AccordionListItem from './components/AccordionList/AccordionListItem';
const App = () => {
return (
<View style={styles.container}>
<AccordionListItem title={'List Item'}>
<Text>Some body text!</Text>
</AccordionListItem>
</View>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
padding: '2rem',
paddingTop: '5rem',
justifyContent: 'flex-start',
},
});
import React, { useState, useRef } from 'react';
import {
View,
Text,
TouchableWithoutFeedback,
StyleSheet,
Animated,
Easing,
} from 'react-native';
import { MaterialIcons } from '@expo/vector-icons';
const AccordionListItem = ({ title, children }) => {
const [open, setOpen] = useState(false);
const animatedController = useRef(new Animated.Value(0)).current;
const [bodySectionHeight, setBodySectionHeight] = useState();
const bodyHeight = animatedController.interpolate({
inputRange: [0, 1],
outputRange: [0, bodySectionHeight],
});
const arrowAngle = animatedController.interpolate({
inputRange: [0, 1],
outputRange: ['0rad', `${Math.PI}rad`],
});
const toggleListItem = () => {
if (open) {
Animated.timing(animatedController, {
duration: 300,
toValue: 0,
easing: Easing.bezier(0.4, 0.0, 0.2, 1),
}).start();
} else {
Animated.timing(animatedController, {
duration: 300,
toValue: 1,
easing: Easing.bezier(0.4, 0.0, 0.2, 1),
}).start();
}
setOpen(!open);
};
return (
<>
<TouchableWithoutFeedback onPress={() => toggleListItem()}>
<View style={styles.titleContainer}>
<Text>{title}</Text>
<Animated.View style={{ transform: [{ rotateZ: arrowAngle }] }}>
<MaterialIcons name="keyboard-arrow-down" size={20} color="black" />
</Animated.View>
</View>
</TouchableWithoutFeedback>
<Animated.View style={[styles.bodyBackground, { height: bodyHeight }]}>
<View
style={styles.bodyContainer}
onLayout={event =>
setBodySectionHeight(event.nativeEvent.layout.height)
}>
{children}
</View>
</Animated.View>
</>
);
};
export default AccordionListItem;
const styles = StyleSheet.create({
bodyBackground: {
backgroundColor: '#EFEFEF',
overflow: 'hidden',
},
titleContainer: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: '1rem',
paddingLeft: '1.5rem',
borderTopWidth: 1,
borderBottomWidth: 1,
borderColor: '#EFEFEF',
},
bodyContainer: {
padding: '1rem',
paddingLeft: '1.5rem',
position: 'absolute',
bottom: 0,
},
});
import*as React from'React';
从“react native”导入{SafeAreaView,Text,View,StyleSheet};
从“expo常量”导入常量;
从“./components/AccordionList/AccordionListItem”导入AccordionListItem;
常量应用=()=>{
返回(
一些正文!
);
};
导出默认应用程序;
const styles=StyleSheet.create({
容器:{
弹性:1,
填充:“2rem”,
paddingTop:'5rem',
justifyContent:“flex start”,
},
});
AccordionListItem.js
import * as React from 'react';
import { SafeAreaView, Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
import AccordionListItem from './components/AccordionList/AccordionListItem';
const App = () => {
return (
<View style={styles.container}>
<AccordionListItem title={'List Item'}>
<Text>Some body text!</Text>
</AccordionListItem>
</View>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
padding: '2rem',
paddingTop: '5rem',
justifyContent: 'flex-start',
},
});
import React, { useState, useRef } from 'react';
import {
View,
Text,
TouchableWithoutFeedback,
StyleSheet,
Animated,
Easing,
} from 'react-native';
import { MaterialIcons } from '@expo/vector-icons';
const AccordionListItem = ({ title, children }) => {
const [open, setOpen] = useState(false);
const animatedController = useRef(new Animated.Value(0)).current;
const [bodySectionHeight, setBodySectionHeight] = useState();
const bodyHeight = animatedController.interpolate({
inputRange: [0, 1],
outputRange: [0, bodySectionHeight],
});
const arrowAngle = animatedController.interpolate({
inputRange: [0, 1],
outputRange: ['0rad', `${Math.PI}rad`],
});
const toggleListItem = () => {
if (open) {
Animated.timing(animatedController, {
duration: 300,
toValue: 0,
easing: Easing.bezier(0.4, 0.0, 0.2, 1),
}).start();
} else {
Animated.timing(animatedController, {
duration: 300,
toValue: 1,
easing: Easing.bezier(0.4, 0.0, 0.2, 1),
}).start();
}
setOpen(!open);
};
return (
<>
<TouchableWithoutFeedback onPress={() => toggleListItem()}>
<View style={styles.titleContainer}>
<Text>{title}</Text>
<Animated.View style={{ transform: [{ rotateZ: arrowAngle }] }}>
<MaterialIcons name="keyboard-arrow-down" size={20} color="black" />
</Animated.View>
</View>
</TouchableWithoutFeedback>
<Animated.View style={[styles.bodyBackground, { height: bodyHeight }]}>
<View
style={styles.bodyContainer}
onLayout={event =>
setBodySectionHeight(event.nativeEvent.layout.height)
}>
{children}
</View>
</Animated.View>
</>
);
};
export default AccordionListItem;
const styles = StyleSheet.create({
bodyBackground: {
backgroundColor: '#EFEFEF',
overflow: 'hidden',
},
titleContainer: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: '1rem',
paddingLeft: '1.5rem',
borderTopWidth: 1,
borderBottomWidth: 1,
borderColor: '#EFEFEF',
},
bodyContainer: {
padding: '1rem',
paddingLeft: '1.5rem',
position: 'absolute',
bottom: 0,
},
});
import React,{useState,useRef}来自“React”;
进口{
看法
文本,
可触摸且无反馈,
样式表,
有生气的
缓和,,
}从“反应本机”;
从“@expo/vector icons”导入{MaterialIcons};
const AccordionListItem=({title,children})=>{
const[open,setOpen]=useState(false);
const animatedController=useRef(新的Animated.Value(0)).current;
const[bodySectionHeight,setBodySectionHeight]=useState();
const bodyHeight=animatedController.interpolate({
输入范围:[0,1],
outputRange:[0,bodySectionHeight],
});
常量arrowAngle=animatedController.interpolate({
输入范围:[0,1],
outputRange:['0rad',`${Math.PI}rad`],
});
常量toggleListItem=()=>{
如果(打开){
动画。计时(动画控制器{
持续时间:300,
toValue:0,
放松:放松。贝塞尔(0.4,0.0,0.2,1),
}).start();
}否则{
动画。计时(动画控制器{
持续时间:300,
toValue:1,
放松:放松。贝塞尔(0.4,0.0,0.2,1),
}).start();
}
setOpen(!open);
};
返回(
toggleListItem()}>
{title}
setBodySectionHeight(event.nativeEvent.layout.height)
}>
{儿童}
);
};
导出默认的AccordionListItem;
const styles=StyleSheet.create({
车身背景:{
背景颜色:“#EFEFEF”,
溢出:“隐藏”,
},
标题容器:{
显示:“flex”,
flexDirection:'行',
justifyContent:'之间的空间',
对齐项目:“居中”,
填充:“1rem”,
填充左:“1.5rem”,
边框宽度:1,
边界宽度:1,
边框颜色:“#EFEFEF”,
},
车身集装箱:{
填充:“1rem”,
填充左:“1.5rem”,
位置:'绝对',
底部:0,
},
});
您收到的错误消息是什么?没有错误..您可以尝试扫描二维码,看看它是否在您的设备中运行。不尝试它,但如果它符合您的目的,您可以在您的示例中尝试它在零食中不起作用。。你能给我看看works零食吗?这正是我需要的,但我希望有一个代码可以工作