Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rev: Reverted dynamic link detect because of UI issue #279

Merged
merged 1 commit into from
Feb 24, 2024
Merged
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
20 changes: 10 additions & 10 deletions DarockBili.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_ENTITLEMENTS = "MeowBili/MeowBili Vision App.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 846;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1496,7 +1496,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_ENTITLEMENTS = "MeowBili/MeowBili Vision App.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 846;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1533,7 +1533,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MeowBili/MeowBili.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 846;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1580,7 +1580,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MeowBili/MeowBili.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 846;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1624,7 +1624,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIconWatch;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 846;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview\\ Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1660,7 +1660,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIconWatch;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 846;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview\\ Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1699,7 +1699,7 @@
CODE_SIGN_ENTITLEMENTS = "MeowBili/MeowBili Mac App.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 846;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -1732,7 +1732,7 @@
CODE_SIGN_ENTITLEMENTS = "MeowBili/MeowBili Mac App.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 846;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -1761,7 +1761,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 846;
DEVELOPMENT_TEAM = B57D8PP775;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
Expand All @@ -1784,7 +1784,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 846;
DEVELOPMENT_TEAM = B57D8PP775;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
Expand Down
1 change: 1 addition & 0 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -8644,6 +8644,7 @@
}
},
"文本加载失败" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
Expand Down
110 changes: 58 additions & 52 deletions MeowBili/Others/LinkDetectText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,53 @@
@State var markdownText = try! AttributedString(markdown: "")
@State var linkColor = Color.blue
@State var error: Error?
@State var isFinishedLoad = false
var body: some View {
Group {
if let error {
VStack(alignment: .leading, content: {
Text("文本加载失败")
Text(error.localizedDescription)
.font(.footnote)
})
} else {
Text(markdownText)
.tint(linkColor)
#if os(watchOS)
//拦截,然后用暗礁浏览器打开
.environment(\.openURL, OpenURLAction(handler: { url in
//加一个小动画,因为下一步操作【真机上】会卡1秒
bling()
// Source: https://www.reddit.com/r/apple/comments/rcn2h7/comment/hnwr8do/
let session = ASWebAuthenticationSession(
url: url,
callbackURLScheme: nil
) { _, _ in
}

// Makes the "Watch App Wants To Use example.com to Sign In" popup not show up
session.prefersEphemeralWebBrowserSession = true

session.start()
return .handled
}))
//iOS端可以直接用系统浏览器打开链接,不需要拦截
#endif
}
}
.onAppear {
loadText(inputURL: inputURL)
}
.onChange(of: inputURL, perform: { newValue in
loadText(inputURL: newValue)
})
.animation(.smooth, value: markdownText)

// Group {
// if let error {
// VStack(alignment: .leading, content: {
// Text("文本加载失败")
// Text(error.localizedDescription)
// .font(.footnote)
// })
// } else {
// Text(markdownText)
// .tint(linkColor)
// #if os(watchOS)
// //拦截,然后用暗礁浏览器打开
// .environment(\.openURL, OpenURLAction(handler: { url in
// //加一个小动画,因为下一步操作【真机上】会卡1秒
// bling()
// // Source: https://www.reddit.com/r/apple/comments/rcn2h7/comment/hnwr8do/
// let session = ASWebAuthenticationSession(
// url: url,
// callbackURLScheme: nil
// ) { _, _ in
// }
//

Check notice on line 51 in MeowBili/Others/LinkDetectText.swift

View check run for this annotation

Xcode Cloud / DarockBili | Analysis | Build - iOS

MeowBili/Others/LinkDetectText.swift#L51

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
// // Makes the "Watch App Wants To Use example.com to Sign In" popup not show up
// session.prefersEphemeralWebBrowserSession = true
//

Check notice on line 54 in MeowBili/Others/LinkDetectText.swift

View check run for this annotation

Xcode Cloud / DarockBili | Analysis | Build - iOS

MeowBili/Others/LinkDetectText.swift#L54

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
// session.start()
// return .handled
// }))
// //iOS端可以直接用系统浏览器打开链接,不需要拦截
// #endif
// }
// }
// .onAppear {
// if !isFinishedLoad {
// loadText(inputURL: inputURL)
// isFinishedLoad = true
// }
// }
// .onChange(of: inputURL, perform: { newValue in
// loadText(inputURL: newValue)
// })
// .animation(.smooth, value: markdownText)
// FIXME: The view commented shows empty view when fast scrolling in the dynamic page.

Check notice on line 72 in MeowBili/Others/LinkDetectText.swift

View check run for this annotation

Xcode Cloud / DarockBili | Analysis | Build - iOS

MeowBili/Others/LinkDetectText.swift#L72

Todo Violation: FIXMEs should be resolved (The view commented shows empty...) (todo)
// Tip: Reverted on February 24, 2024
Text(inputURL)
}
func loadText(inputURL: String) {
let markdownURLs = detectURLs(in: inputURL)
Expand All @@ -88,19 +94,19 @@
})
}
func detectURLs(in text: String) -> String {
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
let matches = detector?.matches(in: text, options: [], range: NSRange(location: 0, length: text.utf16.count))

var markdownString = text
if let matches = matches {
for match in matches {
if let url = match.url {
let link = "[\(url.absoluteString)](\(url.absoluteString))"
markdownString = markdownString.replacingOccurrences(of: url.absoluteString, with: link)
}
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
let matches = detector?.matches(in: text, options: [], range: NSRange(location: 0, length: text.utf16.count))

var markdownString = text
if let matches = matches {
for match in matches {
if let url = match.url {
let link = "[\(url.absoluteString)](\(url.absoluteString))"
markdownString = markdownString.replacingOccurrences(of: url.absoluteString, with: link)
}
}

return markdownString
}

return markdownString
}
}