Skip to content
Permalink
Browse files

Fix screen rotation dimensions

  • Loading branch information...
koenbok committed May 12, 2016
1 parent 2848823 commit 64b09bba74eef370f7023e4f9a68ee15f44c6bbc
Showing with 41 additions and 9 deletions.
  1. +14 −9 framer/Components/DeviceComponent.coffee
  2. +27 −0 test/tests/DeviceComponentTest.coffee
@@ -214,9 +214,14 @@ class exports.DeviceComponent extends BaseClass
if @_shouldRenderFullScreen()
return Canvas.size

return size =
width: @_device.screenWidth
height: @_device.screenHeight
if @isLandscape
return size =
width: @_device.screenHeight
height: @_device.screenWidth
else
return size =
width: @_device.screenWidth
height: @_device.screenHeight

###########################################################################
# DEVICE TYPE
@@ -455,7 +460,7 @@ class exports.DeviceComponent extends BaseClass

[x, y] = [0, 0]

if @isLandscape()
if @isLandscape
x = offset
y = offset

@@ -490,13 +495,13 @@ class exports.DeviceComponent extends BaseClass
@_update()
@emit("change:orientation", window.orientation)

isPortrait: -> Math.abs(@orientation) is 0
isLandscape: -> !@isPortrait()
@define "isPortrait", get: -> Math.abs(@orientation) % 180 is 0
@define "isLandscape", get: -> !@isPortrait

@define "orientationName",
get: ->
return "portrait" if @isPortrait()
return "landscape" if @isLandscape()
return "portrait" if @isPortrait
return "landscape" if @isLandscape
set: (orientationName) -> @setOrientation(orientationName, false)

rotateLeft: (animate=true) ->
@@ -508,7 +513,7 @@ class exports.DeviceComponent extends BaseClass
@setOrientation(@orientation - 90, animate)

_getOrientationDimensions: (width, height) ->
if @isLandscape() then [height, width] else [width, height]
if @isLandscape then [height, width] else [width, height]

###########################################################################
# HANDS
@@ -122,3 +122,30 @@ describe "DeviceComponent", ->
device.deviceType = "fullscreen"
device.context.run ->
Screen.size.should.eql Canvas.size

it "should return landscape and portrait screen sizes", ->

Screen.size.should.eql Canvas.size

device = new DeviceComponent()

device.deviceType = "nexus-5-black"

device.orientation.should.equal 0
device.isPortrait.should.equal true
device.screenSize.should.eql {width:1080, height:1920}

device.rotateLeft(false)
device.orientation.should.equal 90
device.isPortrait.should.equal false
device.screenSize.should.eql {width:1920, height:1080}

device.rotateRight(false)
device.orientation.should.equal 0
device.isPortrait.should.equal true
device.screenSize.should.eql {width:1080, height:1920}

device.rotateRight(false)
device.orientation.should.equal -90
device.isPortrait.should.equal false
device.screenSize.should.eql {width:1920, height:1080}

0 comments on commit 64b09bb

Please sign in to comment.
You can’t perform that action at this time.