mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
Convert the common code into a ProgressButton
This commit is contained in:
parent
74cb2198f5
commit
6cddffbef3
6 changed files with 66 additions and 37 deletions
|
|
@ -7,6 +7,7 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
63EAA4EB259944450046AB8F /* ProgressButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63EAA4EA259944450046AB8F /* ProgressButton.swift */; };
|
||||
CA378F992466567600A58CE0 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA378F982466567600A58CE0 /* AppState.swift */; };
|
||||
CA39711924495F0E00AFFB77 /* AppStoreButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA39711824495F0E00AFFB77 /* AppStoreButtonStyle.swift */; };
|
||||
CA44901F2463AD34003D8213 /* Tag.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA44901E2463AD34003D8213 /* Tag.swift */; };
|
||||
|
|
@ -64,6 +65,7 @@
|
|||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
63EAA4EA259944450046AB8F /* ProgressButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressButton.swift; sourceTree = "<group>"; };
|
||||
CA378F982466567600A58CE0 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
|
||||
CA39711824495F0E00AFFB77 /* AppStoreButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStoreButtonStyle.swift; sourceTree = "<group>"; };
|
||||
CA44901E2463AD34003D8213 /* Tag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tag.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -142,6 +144,14 @@
|
|||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
63EAA4E9259944340046AB8F /* Common */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
63EAA4EA259944450046AB8F /* ProgressButton.swift */,
|
||||
);
|
||||
path = Common;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
CA538A12255A4F7C00E64DD7 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
|
@ -210,6 +220,7 @@
|
|||
CABFAA1A2592F7D900380FEE /* Frontend */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
63EAA4E9259944340046AB8F /* Common */,
|
||||
CA9FF8552595082000E47BAF /* About */,
|
||||
CAA1CB50255A5D16003FD669 /* SignIn */,
|
||||
CABFAA142592F73000380FEE /* XcodeList */,
|
||||
|
|
@ -458,6 +469,7 @@
|
|||
CABFAA432593104F00380FEE /* AboutView.swift in Sources */,
|
||||
CABFA9CC2592EEEA00380FEE /* Path+.swift in Sources */,
|
||||
CAD2E7A22449574E00113D76 /* XcodesApp.swift in Sources */,
|
||||
63EAA4EB259944450046AB8F /* ProgressButton.swift in Sources */,
|
||||
CA5D781E257365D6008EDE9D /* PinCodeTextView.swift in Sources */,
|
||||
CA39711924495F0E00AFFB77 /* AppStoreButtonStyle.swift in Sources */,
|
||||
);
|
||||
|
|
|
|||
34
Xcodes/Frontend/Common/ProgressButton.swift
Normal file
34
Xcodes/Frontend/Common/ProgressButton.swift
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// ProgressButton.swift
|
||||
// Xcodes
|
||||
//
|
||||
// Created by Chad Sykes on 2020-12-27.
|
||||
// Copyright © 2020 Robots and Pencils. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ProgressButton<Label: View>: View {
|
||||
let isInProgress: Bool
|
||||
let action: () -> Void
|
||||
let label: () -> Label
|
||||
|
||||
init(isInProgress: Bool, action: @escaping () -> Void, @ViewBuilder label: @escaping () -> Label) {
|
||||
self.isInProgress = isInProgress
|
||||
self.action = action
|
||||
self.label = label
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Button(action: action) {
|
||||
if isInProgress {
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle())
|
||||
.scaleEffect(x: 0.5, y: 0.5, anchor: .center)
|
||||
} else {
|
||||
label()
|
||||
}
|
||||
}
|
||||
.disabled(isInProgress)
|
||||
}
|
||||
}
|
||||
|
|
@ -24,16 +24,12 @@ struct SignIn2FAView: View {
|
|||
.keyboardShortcut(.cancelAction)
|
||||
Button("Send SMS", action: { appState.choosePhoneNumberForSMS(authOptions: authOptions, sessionData: sessionData) })
|
||||
Spacer()
|
||||
if appState.isProcessingRequest {
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle())
|
||||
.scaleEffect(x: 0.5, y: 0.5, anchor: .center)
|
||||
.padding(.trailing, 22)
|
||||
} else {
|
||||
Button("Continue", action: { appState.submitSecurityCode(.device(code: code), sessionData: sessionData) })
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(code.count != authOptions.securityCode.length)
|
||||
ProgressButton(isInProgress: appState.isProcessingAuthRequest,
|
||||
action: { appState.submitSecurityCode(.device(code: code), sessionData: sessionData) }) {
|
||||
Text("Continue")
|
||||
}
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(code.count != authOptions.securityCode.length)
|
||||
}
|
||||
.frame(height: 25)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,16 +28,12 @@ struct SignInCredentialsView: View {
|
|||
Spacer()
|
||||
Button("Cancel") { isPresented = false }
|
||||
.keyboardShortcut(.cancelAction)
|
||||
if appState.isProcessingRequest {
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle())
|
||||
.scaleEffect(x: 0.5, y: 0.5, anchor: .center)
|
||||
.padding(.horizontal, 8)
|
||||
} else {
|
||||
Button("Next") { appState.signIn(username: username, password: password) }
|
||||
.disabled(username.isEmpty)
|
||||
.keyboardShortcut(.defaultAction)
|
||||
ProgressButton(isInProgress: appState.isProcessingAuthRequest,
|
||||
action: { appState.signIn(username: username, password: password) }) {
|
||||
Text("Next")
|
||||
}
|
||||
.disabled(username.isEmpty || password.isEmpty)
|
||||
.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
.frame(height: 25)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,17 +28,12 @@ struct SignInPhoneListView: View {
|
|||
Button("Cancel", action: { isPresented = false })
|
||||
.keyboardShortcut(.cancelAction)
|
||||
Spacer()
|
||||
|
||||
if appState.isProcessingRequest {
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle())
|
||||
.scaleEffect(x: 0.5, y: 0.5, anchor: .center)
|
||||
.padding(.trailing, 22)
|
||||
} else {
|
||||
Button("Continue", action: { appState.requestSMS(to: authOptions.trustedPhoneNumbers!.first { $0.id == selectedPhoneNumberID }!, authOptions: authOptions, sessionData: sessionData) })
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(selectedPhoneNumberID == nil)
|
||||
ProgressButton(isInProgress: appState.isProcessingAuthRequest,
|
||||
action: { appState.requestSMS(to: authOptions.trustedPhoneNumbers!.first { $0.id == selectedPhoneNumberID }!, authOptions: authOptions, sessionData: sessionData) }) {
|
||||
Text("Continue")
|
||||
}
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(selectedPhoneNumberID == nil)
|
||||
}
|
||||
.frame(height: 25)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,16 +24,12 @@ struct SignInSMSView: View {
|
|||
Button("Cancel", action: { isPresented = false })
|
||||
.keyboardShortcut(.cancelAction)
|
||||
Spacer()
|
||||
if appState.isProcessingRequest {
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle())
|
||||
.scaleEffect(x: 0.5, y: 0.5, anchor: .center)
|
||||
.padding(.trailing, 22)
|
||||
} else {
|
||||
Button("Continue", action: { appState.submitSecurityCode(.sms(code: code, phoneNumberId: trustedPhoneNumber.id), sessionData: sessionData) })
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(code.count != authOptions.securityCode.length)
|
||||
ProgressButton(isInProgress: appState.isProcessingAuthRequest,
|
||||
action: { appState.submitSecurityCode(.sms(code: code, phoneNumberId: trustedPhoneNumber.id), sessionData: sessionData) }) {
|
||||
Text("Continue")
|
||||
}
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(code.count != authOptions.securityCode.length)
|
||||
}
|
||||
.frame(height: 25)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue