Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AltSwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
2CD1A04E2512066D00E2CCBA /* AltSwiftUI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CD1A00D2512066D00E2CCBA /* AltSwiftUI.h */; settings = {ATTRIBUTES = (Public, ); }; };
2CD1A056251206C200E2CCBA /* ViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD1A054251206C200E2CCBA /* ViewTests.swift */; };
68CBD3E12578AADB00A3F033 /* SecureField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68CBD3E02578AADB00A3F033 /* SecureField.swift */; };
714D6C84265F6629003F2682 /* ProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 714D6C83265F6629003F2682 /* ProgressView.swift */; };
7D2D4D6B25148269000F5DDC /* Capsule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2D4D6525148269000F5DDC /* Capsule.swift */; };
7D2D4D6C25148269000F5DDC /* Circle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2D4D6625148269000F5DDC /* Circle.swift */; };
7D2D4D6D25148269000F5DDC /* Ellipse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2D4D6725148269000F5DDC /* Ellipse.swift */; };
Expand Down Expand Up @@ -167,6 +168,7 @@
2CD1A054251206C200E2CCBA /* ViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewTests.swift; sourceTree = "<group>"; };
2CD1A055251206C200E2CCBA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
68CBD3E02578AADB00A3F033 /* SecureField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureField.swift; sourceTree = "<group>"; };
714D6C83265F6629003F2682 /* ProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressView.swift; sourceTree = "<group>"; };
7D2D4D6525148269000F5DDC /* Capsule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Capsule.swift; sourceTree = "<group>"; };
7D2D4D6625148269000F5DDC /* Circle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Circle.swift; sourceTree = "<group>"; };
7D2D4D6725148269000F5DDC /* Ellipse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Ellipse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -355,6 +357,7 @@
2CD19FEA2512066D00E2CCBA /* ReadOnly */ = {
isa = PBXGroup;
children = (
714D6C83265F6629003F2682 /* ProgressView.swift */,
2CD19FF02512066D00E2CCBA /* Color.swift */,
2CD19FEE2512066D00E2CCBA /* Divider.swift */,
2CD19FF22512066D00E2CCBA /* GeometryReader.swift */,
Expand Down Expand Up @@ -638,6 +641,7 @@
2CD1A01C2512066D00E2CCBA /* StateObject.swift in Sources */,
2CD1A03F2512066D00E2CCBA /* TabView.swift in Sources */,
2CD1A0372512066D00E2CCBA /* GeometryReader.swift in Sources */,
714D6C84265F6629003F2682 /* ProgressView.swift in Sources */,
2CD1A03D2512066D00E2CCBA /* CoreViews.swift in Sources */,
2CD1A0212512066D00E2CCBA /* UIKitCoreViews.swift in Sources */,
);
Expand Down
4 changes: 4 additions & 0 deletions Example/AltSwiftUIExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
2CFE2AC025AD487800C925FC /* ScrollView2AxisExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CFE2ABF25AD487800C925FC /* ScrollView2AxisExampleView.swift */; };
35D1A58825C7EDA100861DC4 /* AlertsExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35D1A58525C7EDA100861DC4 /* AlertsExampleView.swift */; };
682C3A7C2594B18A005E798E /* SecureFieldExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 682C3A7B2594B18A005E798E /* SecureFieldExampleView.swift */; };
714D6C8B265F69CD003F2682 /* ProgressViewExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 714D6C8A265F69CD003F2682 /* ProgressViewExampleView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -100,6 +101,7 @@
2CFE2ABF25AD487800C925FC /* ScrollView2AxisExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollView2AxisExampleView.swift; sourceTree = "<group>"; };
35D1A58525C7EDA100861DC4 /* AlertsExampleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertsExampleView.swift; sourceTree = "<group>"; };
682C3A7B2594B18A005E798E /* SecureFieldExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureFieldExampleView.swift; sourceTree = "<group>"; };
714D6C8A265F69CD003F2682 /* ProgressViewExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressViewExampleView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -143,6 +145,7 @@
2C83ED512554E50400C378DC /* NavigationExampleView.swift */,
2CADC30E251CA0DF00EA3F17 /* RamenExampleView.swift */,
682C3A7B2594B18A005E798E /* SecureFieldExampleView.swift */,
714D6C8A265F69CD003F2682 /* ProgressViewExampleView.swift */,
2CFE2ABF25AD487800C925FC /* ScrollView2AxisExampleView.swift */,
2CADC316251CA15400EA3F17 /* ShapesExampleView.swift */,
2C49E3CB2535382F00543E7D /* TextExampleView.swift */,
Expand Down Expand Up @@ -384,6 +387,7 @@
2CE5E28B231398D70072F907 /* AppDelegate.swift in Sources */,
2CDCE7F325C40D2500BB52D1 /* StackUpdateExample.swift in Sources */,
2C0BE74C2521CEE800B37BA9 /* ListExampleView.swift in Sources */,
714D6C8B265F69CD003F2682 /* ProgressViewExampleView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// ProgressViewExampleView.swift
// AltSwiftUIExample
//
// Created by Tsuchiya, Hiroma | Hiroma | TID on 2021/05/27.
// Copyright © 2021 Rakuten Travel. All rights reserved.
//

import AltSwiftUI

struct ProgressViewExampleView: View {
var viewStore = ViewValues()
@State private var progressValue: Float = 0.7

var body: View {
VStack() {
Spacer()

HStack {
Spacer()
ProgressView()
Spacer()
ProgressView("Now loading...")
Spacer()
}

Spacer()

Divider()

Spacer()

Button {
progressValue = Float.random(in: 0..<1)
} label: { () -> View in
Text("Set a random progress value")
}

Text(String(floor(progressValue * 100)) + "%")
.padding(.bottom, 16)

ProgressView(progressValue)
.frame(maxWidth: .infinity)

ProgressView("Downloading...", value: progressValue, total: 1.0)
.frame(maxWidth: .infinity)

Spacer()
}
.frame(maxWidth: .infinity)
}
}
1 change: 1 addition & 0 deletions Example/AltSwiftUIExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct ExampleView: View {
ExampleViewData(title: "Shapes", destination: ShapesExampleView()),
ExampleViewData(title: "Stack Update", destination: StackUpdateExample()),
ExampleViewData(title: "Texts", destination: TextExampleView()),
ExampleViewData(title: "ProgressView", destination: ProgressViewExampleView()),
ExampleViewData(title: "Ramen Example", destination: RamenExampleView())

]
Expand Down
120 changes: 120 additions & 0 deletions Sources/AltSwiftUI/Source/Views/ReadOnly/ProgressView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//
// ProgressView.swift
// AltSwiftUI
//
// Created by Tsuchiya, Hiroma | Hiroma | TID on 2021/05/27.
// Copyright © 2021 Rakuten Travel. All rights reserved.
//

import UIKit

/// A view that shows the progress towards completion of a task.
public struct ProgressView: View {
public var viewStore = ViewValues()
public var body: View {
self
}

var title: String?
var label: View?
var progress: Float?
var total: Float?

public init() {}

public init(_ title: String) {
self.title = title
}

public init(label: View) {
self.label = label
}

public init(_ progress: Float) {
self.progress = progress
}

public init(value: Float?, total: Float? = 1.0) {
self.progress = (value ?? 0) / (total ?? 1.0)
}

public init(_ title: String, value: Float?, total: Float?) {
self.title = title
self.progress = (value ?? 0) / (total ?? 1.0)
}
}

extension ProgressView: Renderable {
public func createView(context: Context) -> UIView {
if (progress != nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this 4 view creation flows to a separate function each, and call them from this function, in order to make this one cleaner.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed plz check

/// Determinate Progress View
if (title != nil) {
return makeDeterminateProgressViewWithTitle(title: title!, context: context)
} else {
return makeDeterminateProgressView(context: context)
}
} else {
/// Indeterminate Progress View
if (title != nil) {
return makeIndeterminateProgressViewWithTitle(title: title!)
} else {
return makeIndeterminateProgressView()
}
}
}

public func updateView(_ view: UIView, context: Context) {
if let progressView = view as? UIProgressView {
progressView.setProgress(progress ?? 0, animated: true)
} else if let uiStackView = view as? UIStackView {
if let progressView = uiStackView.subviews.last as? UIProgressView {
progressView.setProgress(progress ?? 0, animated: true)
}
}
}

func makeDeterminateProgressViewWithTitle(title: String, context: Context) -> UIStackView {
let titleView = UILabel()
titleView.text = title
titleView.textColor = .gray
titleView.font = .systemFont(ofSize: 14)
let progressView = UIProgressView(progressViewStyle: .default)
updateView(progressView, context: context)
let view = UIStackView()
view.axis = .vertical
view.alignment = .leading
view.addArrangedSubview(titleView)
view.addArrangedSubview(progressView)
progressView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
return view
}

func makeDeterminateProgressView(context: Context) -> UIProgressView {
let view = UIProgressView(progressViewStyle: .default)
updateView(view, context: context)
return view
}

func makeIndeterminateProgressViewWithTitle(title: String) -> UIStackView {
let indicatorView = UIActivityIndicatorView(style: .whiteLarge)
indicatorView.color = .gray
indicatorView.startAnimating()
let titleView = UILabel()
titleView.text = title
titleView.font = .systemFont(ofSize: 14)
titleView.textColor = .gray
let view = UIStackView()
view.axis = .vertical
view.alignment = .center
view.addArrangedSubview(indicatorView)
view.addArrangedSubview(titleView)
return view
}

func makeIndeterminateProgressView() -> UIActivityIndicatorView {
let view = UIActivityIndicatorView(style: .whiteLarge)
view.color = .gray
view.startAnimating()
return view
}
}