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

Renamed to LicenseViewStyle from LicenseListViewStyle #43

Merged
merged 1 commit into from
Jul 8, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ let vc = LicenseListViewController()
vc.title = "LICENSE"

// If you want to anchor link of the repository
vc.licenseListViewStyle = .withRepositoryAnchorLink
vc.licenseViewStyle = .withRepositoryAnchorLink

navigationController?.pushViewController(vc, animated: true)
```
Expand All @@ -100,7 +100,7 @@ struct ContentView: View {
NavigationView {
LicenseListView()
// If you want to anchor link of the repository
.licenseListViewStyle(.withRepositoryAnchorLink)
.licenseViewStyle(.withRepositoryAnchorLink)
.navigationTitle("LICENSE")
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/LicenseList/LicenseListView.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

public struct LicenseListView: View {
@Environment(\.licenseListViewStyle) private var licenseListViewStyle: LicenseListViewStyle
@Environment(\.licenseViewStyle) private var licenseViewStyle: LicenseViewStyle

let libraries = Library.libraries
let navigationHandler: ((Library) -> Void)?
Expand Down Expand Up @@ -29,7 +29,7 @@ public struct LicenseListView: View {
} else {
NavigationLink {
LicenseView(library: library)
.licenseListViewStyle(licenseListViewStyle)
.licenseViewStyle(licenseViewStyle)
} label: {
Text(library.name)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/LicenseList/LicenseListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit
import SwiftUI

public class LicenseListViewController: UIViewController {
public var licenseListViewStyle: LicenseListViewStyle = .plain
public var licenseViewStyle: LicenseViewStyle = .plain

public init() {
super.init(nibName: nil, bundle: nil)
Expand All @@ -29,7 +29,7 @@ public class LicenseListViewController: UIViewController {

private func navigateTo(library: Library) {
let hostingController = UIHostingController(
rootView: LicenseView(library: library).licenseListViewStyle(licenseListViewStyle)
rootView: LicenseView(library: library).licenseViewStyle(licenseViewStyle)
)
hostingController.title = library.name
self.navigationController?.pushViewController(hostingController, animated: true)
Expand Down
19 changes: 0 additions & 19 deletions Sources/LicenseList/LicenseListViewStyle.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/LicenseList/LicenseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public struct LicenseView: View {
@State private var attributedLicenseBody = AttributedString(stringLiteral: "")

@Environment(\.openURL) private var openURL: OpenURLAction
@Environment(\.licenseListViewStyle) private var licenseListViewStyle: LicenseListViewStyle
@Environment(\.licenseViewStyle) private var licenseViewStyle: LicenseViewStyle

private let library: Library

Expand All @@ -23,7 +23,7 @@ public struct LicenseView: View {
}
}
.navigationBarTitle(library.name)
._licenseListViewStyle(licenseListViewStyle) {
._licenseViewStyle(licenseViewStyle) {
if let url = library.url {
openURL(url)
}
Expand Down
17 changes: 17 additions & 0 deletions Sources/LicenseList/LicenseViewStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import SwiftUI

public enum LicenseViewStyle {
case plain
case withRepositoryAnchorLink
}

struct LicenseViewStyleKey: EnvironmentKey {
static var defaultValue: LicenseViewStyle = .plain
}

extension EnvironmentValues {
var licenseViewStyle: LicenseViewStyle {
get { self[LicenseViewStyleKey.self] }
set { self[LicenseViewStyleKey.self] = newValue }
}
}
6 changes: 3 additions & 3 deletions Sources/LicenseList/View+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension View {
}
}

func _licenseListViewStyle(_ style: LicenseListViewStyle, action: @escaping () -> Void) -> some View {
func _licenseViewStyle(_ style: LicenseViewStyle, action: @escaping () -> Void) -> some View {
Group {
switch style {
case .plain:
Expand All @@ -24,7 +24,7 @@ extension View {
}
}

public func licenseListViewStyle(_ style: LicenseListViewStyle) -> some View {
self.environment(\.licenseListViewStyle, style)
public func licenseViewStyle(_ style: LicenseViewStyle) -> some View {
self.environment(\.licenseViewStyle, style)
}
}
Loading