-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed NSAttributeString race condition
+ Made some changes to the LoadingCircle element to make it look better
- Loading branch information
1 parent
b6764eb
commit 9586b60
Showing
6 changed files
with
83 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// +String.swift | ||
// HNReader | ||
// | ||
// Created by Mattia Righetti on 21/07/21. | ||
// | ||
|
||
import Foundation | ||
|
||
extension String { | ||
init?(htmlEncodedString: String) { | ||
guard let data = htmlEncodedString.data(using: .utf8) else { | ||
return nil | ||
} | ||
|
||
let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [ | ||
.documentType: NSAttributedString.DocumentType.html, | ||
.characterEncoding: String.Encoding.utf8.rawValue | ||
] | ||
|
||
guard let attributedString = try? NSAttributedString(data: data, options: options, documentAttributes: nil) else { | ||
return nil | ||
} | ||
|
||
self.init(attributedString.string) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// LoadingCircle.swift | ||
// HNReader | ||
// | ||
// Created by Mattia Righetti on 21/07/21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct LoadingCircle: View { | ||
@State private var isLoading = false | ||
|
||
var body: some View { | ||
ZStack { | ||
Circle() | ||
.stroke(Color.gray.opacity(0.5), lineWidth: 10) | ||
.frame(width: 50, height: 50) | ||
|
||
Circle() | ||
.trim(from: 0, to: 0.2) | ||
.stroke(Color.green.opacity(0.7), style: .init(lineWidth: 7, lineCap: .round)) | ||
.frame(width: 50, height: 50) | ||
.rotationEffect(Angle(degrees: isLoading ? 360 : 0)) | ||
.animation( | ||
Animation | ||
.linear(duration: 1) | ||
.repeatForever(autoreverses: false) | ||
) | ||
.onAppear() { | ||
self.isLoading = true | ||
} | ||
} | ||
.frame(width: 70, height: 70) | ||
} | ||
} | ||
|
||
struct LoadingCircle_Previews: PreviewProvider { | ||
static var previews: some View { | ||
LoadingCircle() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters