rishabhbhatia / react-native-awesome-alerts

Awesome alerts for React Native, works with iOS and Android.
MIT License
525 stars 71 forks source link

onCancelPressed and onConfirmPressed can not work #78

Closed rizhalmaulana closed 3 years ago

rizhalmaulana commented 3 years ago

const AddTagRegister = () => { const [tagId, setTagId] = useState(''); const [tagData, setTagData] = useState(''); const [tagCycle, setValueCycle] = useState(''); const [tagType, setValueType] = useState(''); const [showAlert, setShowAlert] = useState(false); const [requestAddRegister, errorMessage] = useResults();

const showNotif = () => {
    setShowAlert({
        showAlert: true
    });
};

const hideAlert = () => {
    setShowAlert({
        showAlert: false
    });
};

const onChangeCycle = (value: string) => {
    setValueCycle(value);
};

const onChangeType = (value: string) => {
    setValueType(value);
};

return (
    <View style={styles.viewStyle}>
        <Image style={styles.imageStyle} source={require('../assets/react.jpg')} />
        <View style={styles.itemViewStyle}>
            <MaterialCommunityIcons style={styles.iconStyle} name="identifier" size={24} />
            <TextInput
                autoCapitalize='none'
                autoCorrect={false}
                style={styles.textInputStyle}
                placeholder='Please Insert Tag Id'
                autoFocus={true}
                value={tagId}
                onChangeText={setTagId}
            />
        </View>
        <View style={styles.itemViewStyle}>
            <Feather name="command" style={styles.iconStyle} />
            <TextInput
                autoCapitalize='none'
                autoCorrect={false}
                style={styles.textInputStyle}
                placeholder='Please Insert Tag Data'
                value={tagData}
                onChangeText={setTagData}
            />
        </View>
        <View style={styles.viewDropdown}>
            <Dropdown
                style={styles.itemDropdown}
                label="Select Tag Cycle"
                data={dataCycle}
                // enableSearch
                value={tagCycle}
                onChange={onChangeCycle}
            />
            <Dropdown
                style={styles.itemDropdownType}
                label="Select Tag Type"
                data={dataType}
                // enableSearch
                value={tagType}
                onChange={onChangeType}
            />
        </View>
        <View style={styles.viewTouchableStyle}>
            <TouchableOpacity style={styles.touchableStyle} onPress={() => showNotif()}>
                <Text style={{ color: 'white' }}>Save</Text>
            </TouchableOpacity>
            <AwesomeAlert
                show={showAlert}
                showProgress={false}
                title="Information"
                message="Save the Register?"
                closeOnTouchOutside={false}
                closeOnHardwareBackPress={false}
                showCancelButton={true}
                showConfirmButton={true}
                cancelText="No, cancel"
                confirmText="Yes, save it"
                confirmButtonColor="#3a74cf"
                onCancelPressed={() => hideAlert() }
                onConfirmPressed={() => hideAlert() }
            />
        </View>
    </View>
);

};

markstreich commented 3 years ago

I think this is your problem:

-    setShowAlert({
-        showAlert: false
-    });
+    setShowAlert(false);
rishabhbhatia commented 3 years ago

@rizhalmaulana Mark pointed out the correct solution, hope it works now. Use setShowAlert to set boolean values instead of objects.