summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/Extensions/View+TapAreaSize.swift
blob: 4d7666b9dd907c1026ae08a663d42c4fd2a967f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
//  View+TapAreaSize.swift
//  MullvadVPN
//
//  Created by Jon Petersson on 2024-11-13.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import SwiftUI

extension View {
    /// Adjusts tappable area to at least minimum (default) size without changing
    /// actual view size.
    func adjustingTapAreaSize() -> some View {
        modifier(TappablePadding())
    }
}

private struct TappablePadding: ViewModifier {
    @State private var actualViewSize: CGSize = .zero
    private let tappableViewSize = UIMetrics.Button.minimumTappableAreaSize

    func body(content: Content) -> some View {
        content
            .sizeOfView { actualViewSize = $0 }
            .frame(
                width: max(actualViewSize.width, tappableViewSize.width),
                height: max(actualViewSize.height, tappableViewSize.height)
            )
            .contentShape(Rectangle())
    }
}