Browse Source

gracefully toggle controls for collapsed view

Yana Rose 4 years ago
parent
commit
331ff55db5
1 changed files with 18 additions and 0 deletions
  1. 18 0
      src/viewer/index.ts

+ 18 - 0
src/viewer/index.ts

@@ -172,6 +172,24 @@ export class Viewer {
                 timeoutMs: 5000
             })
         }
+        this.prevExpanded = this.plugin.layout.state.isExpanded;
+        this.plugin.layout.events.updated.subscribe(() => this.toggleControls());
+    }
+
+    private prevExpanded: boolean;
+
+    private toggleControls(): void {
+
+        const currExpanded = this.plugin.layout.state.isExpanded;
+        const expanedChanged = (this.prevExpanded !== currExpanded);
+        if (!expanedChanged) return;
+
+        if (currExpanded && !this.plugin.layout.state.showControls) {
+            this.plugin.layout.setProps({showControls: true});
+        } else if (!currExpanded && this.plugin.layout.state.showControls) {
+            this.plugin.layout.setProps({showControls: false});
+        }
+        this.prevExpanded = this.plugin.layout.state.isExpanded;
     }
 
     //