mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	fix(mobile): swiping with very short gesture
This commit is contained in:
		
							parent
							
								
									cdfd2827e8
								
							
						
					
					
						commit
						7fc60bfc8f
					
				| @ -17,6 +17,8 @@ const DRAG_OPENED_START_THRESHOLD = 80; | |||||||
| export default class SidebarContainer extends FlexContainer { | export default class SidebarContainer extends FlexContainer { | ||||||
| 
 | 
 | ||||||
|     private screenName: Screen; |     private screenName: Screen; | ||||||
|  |     /** The screen name that is currently active, according to the screen changed event. */ | ||||||
|  |     private activeScreenName?: Screen; | ||||||
|     private currentTranslate: number; |     private currentTranslate: number; | ||||||
|     private dragState: number; |     private dragState: number; | ||||||
|     private startX?: number; |     private startX?: number; | ||||||
| @ -41,9 +43,7 @@ export default class SidebarContainer extends FlexContainer { | |||||||
|         super.doRender(); |         super.doRender(); | ||||||
| 
 | 
 | ||||||
|         this.$widget.on("click", () => { |         this.$widget.on("click", () => { | ||||||
|             this.triggerCommand('setActiveScreen', { |             this.triggerCommand('setActiveScreen', { screen: "detail" }); | ||||||
|                 screen: "detail" |  | ||||||
|             }); |  | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         document.addEventListener("touchstart", (e) => this.#onDragStart(e)); |         document.addEventListener("touchstart", (e) => this.#onDragStart(e)); | ||||||
| @ -113,7 +113,16 @@ export default class SidebarContainer extends FlexContainer { | |||||||
|         // When the sidebar is open, always close for a smooth experience.
 |         // When the sidebar is open, always close for a smooth experience.
 | ||||||
|         const isOpen = (this.currentTranslate === -100 && this.translatePercentage > -(100 - DRAG_OPEN_THRESHOLD)); |         const isOpen = (this.currentTranslate === -100 && this.translatePercentage > -(100 - DRAG_OPEN_THRESHOLD)); | ||||||
|         const screen = (isOpen ? "tree" : "detail"); |         const screen = (isOpen ? "tree" : "detail"); | ||||||
|  | 
 | ||||||
|  |         if (this.activeScreenName !== screen) { | ||||||
|  |             // Trigger the set active screen command for the rest of the UI to know whether the sidebar is active or not.
 | ||||||
|  |             // This allows the toggle sidebar button to work, by knowing the right state.
 | ||||||
|             this.triggerCommand("setActiveScreen", { screen }); |             this.triggerCommand("setActiveScreen", { screen }); | ||||||
|  |         } else { | ||||||
|  |             // If the active screen hasn't changed, usually due to the user making a very short gesture that results in the sidebar not being closed/opened,
 | ||||||
|  |             // we need to hide the animation but setActiveScreen command will not trigger the event since we are still on the same screen.
 | ||||||
|  |             this.#setSidebarOpen(isOpen); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #setInitialState() { |     #setInitialState() { | ||||||
| @ -153,6 +162,7 @@ export default class SidebarContainer extends FlexContainer { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     activeScreenChangedEvent({activeScreen}: EventData<"activeScreenChanged">) { |     activeScreenChangedEvent({activeScreen}: EventData<"activeScreenChanged">) { | ||||||
|  |         this.activeScreenName = activeScreen; | ||||||
|         this.#setInitialState(); |         this.#setInitialState(); | ||||||
|         this.#setSidebarOpen(activeScreen === this.screenName); |         this.#setSidebarOpen(activeScreen === this.screenName); | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran