Created
March 1, 2018 10:59
-
-
Save filipposarzana/1978bd13b8e95fd268f1b1b1a2ebec8b to your computer and use it in GitHub Desktop.
Window Strategy - Web/Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Window { | |
contructor(type) { | |
switch (type) { | |
case 'Native': | |
this.strategy = new NativeWindow() | |
break; | |
case 'Web': | |
this.strategy = new WebWindow() | |
break; | |
default: | |
throw new Error(`Strategy ${type} not implemented`) | |
} | |
} | |
height = () => this.strategy.height() | |
width = () => this.strategy.width() | |
} | |
class NativeWindow { | |
constructor() { | |
this.window = Dimensions.get('window') | |
} | |
height = () => this.window.height | |
width = () => this.window.width | |
} | |
class WebWindow { | |
height = () => window.height | |
width = () => window.width | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment