Mini Apps: Support fullscreen button and visibility_changed event (#5292)
This commit is contained in:
parent
c0b89697cd
commit
9c635ae7e6
@ -290,6 +290,10 @@
|
|||||||
height: 1.75rem !important;
|
height: 1.75rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fullscreenButton {
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
.tab-close-button {
|
.tab-close-button {
|
||||||
transition: opacity 0.25s ease-in-out;
|
transition: opacity 0.25s ease-in-out;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
|||||||
@ -306,6 +306,10 @@ const WebAppModal: FC<OwnProps & StateProps> = ({
|
|||||||
changeWebAppModalState({ state: 'minimized' });
|
changeWebAppModalState({ state: 'minimized' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleFullscreenClick = useLastCallback(() => {
|
||||||
|
changeWebAppModalState({ state: 'fullScreen' });
|
||||||
|
});
|
||||||
|
|
||||||
const handleOpenMoreAppsTabClick = useLastCallback(() => {
|
const handleOpenMoreAppsTabClick = useLastCallback(() => {
|
||||||
openMoreAppsTab();
|
openMoreAppsTab();
|
||||||
});
|
});
|
||||||
@ -588,6 +592,20 @@ const WebAppModal: FC<OwnProps & StateProps> = ({
|
|||||||
{renderTabs()}
|
{renderTabs()}
|
||||||
{renderMoreMenu()}
|
{renderMoreMenu()}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className={buildClassName(
|
||||||
|
styles.windowStateButton,
|
||||||
|
styles.fullscreenButton,
|
||||||
|
'no-drag',
|
||||||
|
)}
|
||||||
|
round
|
||||||
|
color="translucent"
|
||||||
|
size="tiny"
|
||||||
|
onClick={handleFullscreenClick}
|
||||||
|
>
|
||||||
|
<Icon className={styles.stateIcon} name="expand-modal" />
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
className={buildClassName(
|
className={buildClassName(
|
||||||
styles.windowStateButton,
|
styles.windowStateButton,
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import renderText from '../../common/helpers/renderText';
|
|||||||
|
|
||||||
import { getIsWebAppsFullscreenSupported } from '../../../hooks/useAppLayout';
|
import { getIsWebAppsFullscreenSupported } from '../../../hooks/useAppLayout';
|
||||||
import useCurrentOrPrev from '../../../hooks/useCurrentOrPrev';
|
import useCurrentOrPrev from '../../../hooks/useCurrentOrPrev';
|
||||||
|
import useEffectWithPrevDeps from '../../../hooks/useEffectWithPrevDeps';
|
||||||
import useFlag from '../../../hooks/useFlag';
|
import useFlag from '../../../hooks/useFlag';
|
||||||
import useLang from '../../../hooks/useLang';
|
import useLang from '../../../hooks/useLang';
|
||||||
import useLastCallback from '../../../hooks/useLastCallback';
|
import useLastCallback from '../../../hooks/useLastCallback';
|
||||||
@ -326,6 +327,30 @@ const WebAppModalTabContent: FC<OwnProps & StateProps> = ({
|
|||||||
}
|
}
|
||||||
}, [isFullscreen]);
|
}, [isFullscreen]);
|
||||||
|
|
||||||
|
const visibilityChangedCallBack = useLastCallback((visibility: boolean) => {
|
||||||
|
sendEvent({
|
||||||
|
eventType: 'visibility_changed',
|
||||||
|
eventData: {
|
||||||
|
is_visible: visibility,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isLoaded) {
|
||||||
|
visibilityChangedCallBack(Boolean(isActive));
|
||||||
|
}
|
||||||
|
}, [isActive, isLoaded]);
|
||||||
|
|
||||||
|
useEffectWithPrevDeps(([prevModalState]) => {
|
||||||
|
if (modalState === 'minimized') {
|
||||||
|
visibilityChangedCallBack(false);
|
||||||
|
}
|
||||||
|
if (modalState && prevModalState === 'minimized') {
|
||||||
|
visibilityChangedCallBack(true);
|
||||||
|
}
|
||||||
|
}, [modalState]);
|
||||||
|
|
||||||
useSyncEffect(([prevIsPaymentModalOpen]) => {
|
useSyncEffect(([prevIsPaymentModalOpen]) => {
|
||||||
if (isPaymentModalOpen === prevIsPaymentModalOpen) return;
|
if (isPaymentModalOpen === prevIsPaymentModalOpen) return;
|
||||||
if (webApp?.slug && !isPaymentModalOpen && paymentStatus) {
|
if (webApp?.slug && !isPaymentModalOpen && paymentStatus) {
|
||||||
|
|||||||
@ -152,6 +152,9 @@ export type WebAppOutboundEvent =
|
|||||||
WebAppEvent<'fullscreen_changed', {
|
WebAppEvent<'fullscreen_changed', {
|
||||||
is_fullscreen: boolean;
|
is_fullscreen: boolean;
|
||||||
}> |
|
}> |
|
||||||
|
WebAppEvent<'visibility_changed', {
|
||||||
|
is_visible: boolean;
|
||||||
|
}> |
|
||||||
WebAppEvent<'fullscreen_failed', {
|
WebAppEvent<'fullscreen_failed', {
|
||||||
error: 'UNSUPPORTED' | string;
|
error: 'UNSUPPORTED' | string;
|
||||||
}> |
|
}> |
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user