<commit_before>//
//  ConditionalProgress.swift
//  ZamzamUI
//
//  Created by <NAME> on 2020-10-16.
//  Copyright © 2020 Zamzam Inc. All rights reserved.
//

import SwiftUI

/// A modifier that adds a progress view over this view if the condition is met, otherwise it no progress view is shown.
private struct ConditionalProgress: ViewModifier {
    let condition: Bool
    let tint: Color?

    func body(content: Content) -> some View {
        content.modifier(if: condition) { content in
            ZStack {
                content
                if let tint = tint {
                    ProgressView()
                        .progressViewStyle(CircularProgressViewStyle(tint: tint))
                } else {
                    ProgressView()
                }
            }
        } else: { content in
            content
        }
    }
}

public extension View {
    /// Adds a progress view over this view if the condition is met, otherwise it no progress view is shown.
    ///
    /// - Parameter condition: The condition to determine if the content should be applied.<commit_msg>Prevent progress loader to unnecessary re-render view unnecessary<commit_after>//
//  ConditionalProgress.swift
//  ZamzamUI
//
//  Created by <NAME> on 2020-10-16.
//  Copyright © 2020 Zamzam Inc. All rights reserved.
//

import SwiftUI

/// A modifier that adds a progress view over this view if the condition is met, otherwise it no progress view is shown.
private struct ConditionalProgress: ViewModifier {
    let condition: Bool
    let tint: Color?

    func body(content: Content) -> some View {
        content
            .overlay(
                Group {
                    if condition {
                        if let tint = tint {
                            ProgressView()
                                .progressViewStyle(CircularProgressViewStyle(tint: tint))
                        } else {
                            ProgressView()
                        }
                    }
                }
            )
    }
}

public extension View {
    /// Adds a progress view over this view if the condition is met, otherwise it no progress view is shown.
    ///
    /// - Parameter condition: The condition to determine if the content should be applied.
{'fraction_non_alphanumeric': 0.07350352112676056, 'fraction_numerical': 0.01056338028169014, 'mean_word_length': 1.5977142857142856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3224716', 'n_tokens_mistral': 589, 'n_tokens_neox': 543, 'n_words': 217}