Malert icon indicating copy to clipboard operation
Malert copied to clipboard

Issue in landscape mode

Open nemanja-nisic opened this issue 3 years ago • 3 comments

I have a following issue when my app goes to landscape mode. Do you have any suggestions?

IMG_006A143B68F9-1

I would like alert to be a fixed width instead of going almost entire width of the screen. Thanks

nemanja-nisic avatar Oct 18 '21 16:10 nemanja-nisic

Hi @nemanja-nisic, I'm glad that you are using Malert!

Malert does not have this support to set Alert's width, because Malert has an adaptive and flexible layout.

I was thinking here and we can provide a landscape and a portrait margin to be set. Does this approach help you?

vitormesquita avatar Oct 28 '21 19:10 vitormesquita

Hi @vitormesquita Im sorry for the late reply. It could, as long as the margin applies to the entire malert view.

nemanja-nisic avatar Nov 24 '21 12:11 nemanja-nisic

Just had the same issue with landscape mode so I did a small adjustment in MalertPresentTransitioning.swift file and now at least it doesn't take all the screen height and works for me as expected. Maybe someone will helps this.

extension UIWindow {
    static var isLandscape: Bool {
        if #available(iOS 13.0, *) {
            return UIApplication.shared.windows
                .first?
                .windowScene?
                .interfaceOrientation
                .isLandscape ?? false
        } else {
            return UIApplication.shared.statusBarOrientation.isLandscape
        }
    }
}

class MalertPresentTransitioning: BaseTransitioning, UIViewControllerAnimatedTransitioning {
    let containerHeight: CGFloat = 300
    var originFrame: CGRect {
        switch UIDevice.current.userInterfaceIdiom {
        case .phone:
            if UIWindow.isLandscape {
                return CGRect(
                    x: UIScreen.main.bounds.minX,
                    y: UIScreen.main.bounds.midY - containerHeight / 2,
                    width: UIScreen.main.bounds.width,
                    height: containerHeight)
            } else {
                return UIScreen.main.bounds
            }
        case .pad:
            return CGRect(
                x: UIScreen.main.bounds.minX,
                y: UIScreen.main.bounds.midY - containerHeight / 2,
                width: UIScreen.main.bounds.width,
                height: containerHeight)
        default:
            return UIScreen.main.bounds
        }
    }
}

Sangsom avatar Feb 24 '22 15:02 Sangsom