Also, previewSize.height is going to be the smaller dimension, but you're comparing it to the larger dimension of the screen.

The proper comparison involves camera.sensorAngle. If it is 90 or 270 you need to swap width and height.  For now, it might just be good enough to do the Math.min() thing above.

This is hard and I'm not sure how to get it exactly right.  Will require testing on flatfish some other time to fine tune.

But for now, at least be sure you're comparing small dimensions or large dimensions.