Skip to content

Instantly share code, notes, and snippets.

@filipposarzana
Created March 1, 2018 10:59
Show Gist options
  • Save filipposarzana/1978bd13b8e95fd268f1b1b1a2ebec8b to your computer and use it in GitHub Desktop.
Save filipposarzana/1978bd13b8e95fd268f1b1b1a2ebec8b to your computer and use it in GitHub Desktop.
Window Strategy - Web/Native
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