mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	feat(mobile): detect presence of the virtual keyboard
This commit is contained in:
		
							parent
							
								
									1aa69ba268
								
							
						
					
					
						commit
						7a1e775de2
					
				@ -121,7 +121,6 @@ export default class DesktopLayout {
 | 
			
		||||
 | 
			
		||||
        return new RootContainer(true)
 | 
			
		||||
            .setParent(appContext)
 | 
			
		||||
            .class((launcherPaneIsHorizontal ? "horizontal" : "vertical") + "-layout")
 | 
			
		||||
            .optChild(
 | 
			
		||||
                fullWidthTabBar,
 | 
			
		||||
                new FlexContainer("row")
 | 
			
		||||
 | 
			
		||||
@ -122,7 +122,6 @@ export default class MobileLayout {
 | 
			
		||||
    getRootWidget(appContext: typeof AppContext) {
 | 
			
		||||
        return new RootContainer(true)
 | 
			
		||||
            .setParent(appContext)
 | 
			
		||||
            .class("horizontal-layout")
 | 
			
		||||
            .cssBlock(MOBILE_CSS)
 | 
			
		||||
            .child(new FlexContainer("column").id("mobile-sidebar-container"))
 | 
			
		||||
            .child(
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,44 @@
 | 
			
		||||
import utils from "../../services/utils.js";
 | 
			
		||||
import type BasicWidget from "../basic_widget.js";
 | 
			
		||||
import FlexContainer from "./flex_container.js";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The root container is the top-most widget/container, from which the entire layout derives.
 | 
			
		||||
 *
 | 
			
		||||
 * For convenience, the root container has a few class selectors that can be used to target some global state:
 | 
			
		||||
 *
 | 
			
		||||
 * - `#root-container.virtual-keyboard-opened`, on mobile devices if the virtual keyboard is open.
 | 
			
		||||
 * - `#root-container.horizontal-layout`, if the current layout is horizontal.
 | 
			
		||||
 * - `#root-container.vertical-layout`, if the current layout is horizontal.
 | 
			
		||||
 */
 | 
			
		||||
export default class RootContainer extends FlexContainer<BasicWidget> {
 | 
			
		||||
    private originalViewportHeight: number;
 | 
			
		||||
 | 
			
		||||
    constructor(isHorizontalLayout: boolean) {
 | 
			
		||||
        super(isHorizontalLayout ? "column" : "row");
 | 
			
		||||
 | 
			
		||||
        this.id("root-widget");
 | 
			
		||||
        this.css("height", "100dvh");
 | 
			
		||||
        this.class((isHorizontalLayout ? "horizontal" : "vertical") + "-layout");
 | 
			
		||||
        this.originalViewportHeight = getViewportHeight();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    render(): JQuery<HTMLElement> {
 | 
			
		||||
        if (utils.isMobile()) {
 | 
			
		||||
            window.visualViewport?.addEventListener("resize", () => this.#onMobileResize());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return super.render();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #onMobileResize() {
 | 
			
		||||
        const currentViewportHeight = getViewportHeight();
 | 
			
		||||
        const isKeyboardOpened = (currentViewportHeight < this.originalViewportHeight);
 | 
			
		||||
        this.$widget.toggleClass("virtual-keyboard-opened", isKeyboardOpened);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getViewportHeight() {
 | 
			
		||||
    return window.visualViewport?.height ?? window.innerHeight;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user