The translation was generated automatically and may contain mistakes
Module: 4. Development
Lesson 4. Modal windows
The main thing in the lesson
- •
Modal windows block access to other application screens as long as they are open. Pop-up windows are similar to modal windows, but are used to display information of a different nature.
- •
To create a modal window:
- •
Use the component
ModalRootLibrary VKUI. Identify one or more componentsModalPageeach of which corresponds to one modal window.TypeScriptexport const AppModalRoot = () => { ... return ( <ModalRoot activeModal={activeModal} onClose={onClose}> <ModalPage id={EModal.DISH} onClose={onClose}> <DishModal onClose={onClose} /> </ModalPage> </ModalRoot> ); };Instead of
ModalPagecan be usedModalCard. - •
Pass the created component to
SplitLayout:TypeScriptexport const App = () => { <SplitLayout modal={<AppModalRoot />}> // ... </SplitLayout> }
- •
- •
A route can be defined for the modal window. In this case, it will be shown when crossing this route. The modal window can be shown without defining the route. Use this method
RouteNavigator.showModal(...). To hide the modal window, callRouteNavigator.hideModal(). - •
Use Components to Create Pop-Up Windows
Alert,ActionSheet,ScreenSpinnerorPopoutWrapperLibrary VKUI.TypeScriptconst OrderCancelPopout = ({ handleBackButton }: Props) => { ... return ( <Alert header="Прервать оформление заказа?" text="Данные будут утеряны" /> ); };Use a hook
usePopout()to get the installed popout, and pass it toSplitLayout:TypeScriptfunction App() { const routerPopout = usePopout(); ... return ( <SplitLayout popout={routerPopout} ...>...</SplitLayout> ); }; - •
To show the pop-up window, call
RouteNavigator.showPopout(...). To hide the modal window, callRouteNavigator.hidePopout(). The pop-up window is also hidden when you press the Back button in the browser or on a mobile device.
Useful links
- •Client part (source code) ,
Look at the code fragments by #M4L4> - •
- •
- •
- •
- •
:::