我正在尝试直接从样式访问 useTheme() 但到目前为止我的解决方案似乎不起作用。我没有返回错误。有办法做我想做的事吗?
import { StyleSheet } from "react-native";
import { useTheme } from '@react-navigation/native'
export default function () {
const { colors } = useTheme();
const styles = GlobalStyles({ colors: colors })
return styles
}
const GlobalStyles = (props) => StyleSheet.create({
container: {
flex: 1,
backgroundColor: props.colors.backgroundColor,
},
})
Run Code Online (Sandbox Code Playgroud)
访问组件中的样式
import React from "react";
import GlobalStyles from "../globalStyles.js"
class Inventory extends React.Component {
render() {
return (
<View style={globalStyles.container}>
)
}
Run Code Online (Sandbox Code Playgroud) javascript reactjs react-native expo react-native-stylesheet
我正在使用 Foreach 和 DisclosureGroup 来显示数据。每个部分都可以展开/折叠。然而,它们都在同时扩展/折叠。
如何单独展开/折叠每个部分?
struct TasksTabView: View {
@State private var expanded: Bool = false
var body: some View {
ForEach(Array(self.dict!.keys.sorted()), id: \.self) { key in
if let tasks = self.dict![key] {
DisclosureGroup(isExpanded: $expanded) {
ForEach(Array(tasks.enumerated()), id:\.1.title) { (index, task) in
VStack(alignment: .leading, spacing: 40) {
PillForRow(index: index, task: task)
.padding(.bottom, 40)
}.onTapGesture {
self.selectedTask = task
}
}
} label: {
Header(title: key, SubtitleText: Text(""), showTag: true, tagValue: tasks.count)
}.accentColor(.rhinoRed)
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我可以使用字符串显示工作表吗?请告诉我是否有解决方法。
@State var selectedContactInfo: String?
.sheet(item: $selectedContactInfo){ item in MessageView(recipient: selectedContactInfo!) }
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
实例方法“sheet(item:onDismiss:content:)”要求“String”符合“Identifying”