gpt4 book ai didi

javascript - 如何使用带有钩子(Hook)的 react-native-action-sheet

转载 作者:行者123 更新时间:2023-12-03 14:52:54 24 4
gpt4 key购买 nike

我正在尝试使用 https://github.com/expo/react-native-action-sheet在使用提供的钩子(Hook) useActionSheet() 的功能组件中。我已经在使用类组件版本没有任何问题,但我想切换到功能。
react 版本是 16.9.0
这是我的组件

import {
connectActionSheet,
useActionSheet,
} from "@expo/react-native-action-sheet";
import React, { Component } from "react";
import { View, Text, SafeAreaView } from "react-native";
import TaButton from "../components/TaButton";
import { typography, styles, buttons } from "../components/Styles";

const UploadUI: React.FC<{
description: string;
label: string;
}> = (props) => {
const { showActionSheetWithOptions } = useActionSheet();

const openActionSheet = () => {
console.log("TEST - Choosing action now");
const options = [
"Scegli dalla libreria",
"Scatta una foto",
"Carica un file",
"Annulla",
];
//const destructiveButtonIndex = 0;
const cancelButtonIndex = options.length - 1;

showActionSheetWithOptions(
{
options,
cancelButtonIndex,
//destructiveButtonIndex,
},
(buttonIndex) => {
// Do something here depending on the button index selected
switch (buttonIndex) {
case 0:
console.log('Case 0')

return;
case 1:
console.log("Case 1");
return;
case 2:
console.log("Case 2");
return;

default:
}
}
);
};

const { description, label } = props;
return (
<View style={{ flexDirection: "row", height: 50, marginBottom: 30 }}>
<View style={{ flex: 0.7, justifyContent: "center" }}>
<Text style={typography.body}>{description}</Text>
</View>
<View style={{ flex: 0.3 }}>
<TaButton
style={buttons.primary}
labelStyle={buttons.primaryLabel}
onPress={() => openActionSheet()}
label={label}
/>
</View>
</View>
);
};

const URWStep4: React.FC = (props) => {
return (
<SafeAreaView style={styles.container}>
<View style={styles.container}>
<View style={{ paddingVertical: 30, marginBottom: 20 }}>
<Text style={typography.title}>
Ci serviranno alcuni documenti per verificare la tua identità
</Text>
</View>
<UploadUI
description="Carta d'identità - Fronte"
label="Carica"
></UploadUI>
<UploadUI
description="Carta d'identità - Retro"
label="Carica"
></UploadUI>
</View>
</SafeAreaView>
);
};

export default connectActionSheet(URWStep4);
单击按钮时,会记录“测试 - 立即选择操作”这句话,但没有任何 react 。操作表未打开。

最佳答案

检查您是否使用 <ActionSheetProvider /> 包装了您的顶级组件即使使用钩子(Hook)
https://github.com/expo/react-native-action-sheet#1-wrap-your-top-level-component-with-actionsheetprovider-

关于javascript - 如何使用带有钩子(Hook)的 react-native-action-sheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63359628/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com