I think you should have hasPreviewMode in this line, too:

  (hasPreviewMode && !isPortrait &&