Merge pull request #1976 from ecency/nt/action-modal

NT - Action Modal
This commit is contained in:
Feruz M 2021-06-21 22:36:03 +03:00 committed by GitHub
commit dc7f8f4193
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 16 deletions

View File

@ -1,5 +1,5 @@
import React, { useEffect, useRef } from 'react';
import { Alert, AlertButton, ButtonProps } from 'react-native';
import React, { useEffect, useRef, useState } from 'react';
import {AlertButton, ButtonProps } from 'react-native';
import { Source } from 'react-native-fast-image';
import { useSelector, useDispatch } from 'react-redux';
import { ActionModalView } from '..';
@ -19,22 +19,23 @@ const ActionModalContainer = ({ navigation }) => {
const dispatch = useDispatch();
const actionModalRef = useRef<ActionModalRef>();
const actionModalVisible = useSelector(
(state) => state.ui.actionModalVisible,
);
const actionModalData:ActionModalData = useSelector(state => state.ui.actionModalData)
const actionModalVisible = useSelector((state) => state.ui.actionModalVisible);
const actionModalData:ActionModalData = useSelector(state => state.ui.actionModalData)
const [modalToken, setModalToken] = useState(0);
useEffect(() => {
if (actionModalVisible) {
if (actionModalVisible && actionModalVisible !== modalToken) {
actionModalRef.current?.showModal();
setModalToken(actionModalVisible);
}
}, [actionModalVisible]);
const _onClose = () => {
actionModalData.onClosed();
if(actionModalData.onClosed){
actionModalData.onClosed();
}
dispatch(hideActionModal());
};

View File

@ -9,9 +9,14 @@ export default EStyleSheet.create({
paddingBottom:8,
},
sheetContent: {
sheetContent: {
backgroundColor: '$primaryBackgroundColor',
},
position:'absolute',
bottom:0,
left:0,
right:0,
zIndex:999
},
container:{
marginTop:16,

View File

@ -66,7 +66,7 @@ const ActionModalView = ({onClose, data}: ActionModalViewProps, ref) => {
<View style={styles.actionPanel}>
{
{buttons ? (
buttons.map((props)=>(
<TextButton
key={props.text}
@ -79,6 +79,17 @@ const ActionModalView = ({onClose, data}: ActionModalViewProps, ref) => {
textStyle={styles.btnText}
/>
))
):(
<TextButton
key='default'
text='OK'
onPress={()=>{
sheetModalRef.current?.setModalVisible(false);
}}
style={styles.button}
textStyle={styles.btnText}
/>
)
}
</View>
</View>

View File

@ -1,4 +1,5 @@
import { ButtonProps } from 'react-native';
import { AlertButton } from 'react-native';
import {
TOAST_NOTIFICATION,
UPDATE_ACTIVE_BOTTOM_TAB,
@ -20,9 +21,9 @@ export const toastNotification = (payload:string) => ({
type: TOAST_NOTIFICATION,
});
export const showActionModal = (title:string, body:string, buttons:ButtonProps[], headerImage:any, onClosed:()=>void) => ({
export const showActionModal = (title:string, body?:string, buttons?:AlertButton[], headerImage?:any, onClosed?:()=>void) => ({
payload: {
actionModalVisible: true,
actionModalVisible: new Date().getTime(),
actionModalData: {
title,
body,