-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from crane-hiromu/feature/license
ライセンス画面の追加
- Loading branch information
Showing
13 changed files
with
208 additions
and
99 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 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
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
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,6 @@ | ||
import SwiftUI | ||
|
||
// MARK: - Environment | ||
struct LicenseEnvironment: DynamicProperty { | ||
@Environment(\.router) var router | ||
} |
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,59 @@ | ||
import SwiftUI | ||
import Foundation | ||
import Combine | ||
import CombineStorable | ||
|
||
// MARK: - ViewModel | ||
final class LicenseViewModel: NSObject, ObservableObject, Storable { | ||
let input: Input | ||
let output: Output | ||
@ObservedObject var binding: Binding | ||
|
||
init( | ||
input: Input = .init(), | ||
output: Output = .init(), | ||
binding: Binding = .init() | ||
) { | ||
self.input = input | ||
self.output = output | ||
self.binding = binding | ||
super.init() | ||
bind(input: input, output: output, binding: binding) | ||
} | ||
} | ||
|
||
// MARK: - Property | ||
extension LicenseViewModel { | ||
|
||
final class Input { | ||
// NOP | ||
} | ||
|
||
final class Output: ObservableObject { | ||
// fixme: update stencil | ||
let models: [LicenseModel] = [ | ||
LicenseModel(name: PlistFiles.CombineStorable.name, plist: PlistFiles.CombineStorable.preferenceSpecifiers), | ||
LicenseModel(name: PlistFiles.PlaygroundTester.name, plist: PlistFiles.PlaygroundTester.preferenceSpecifiers), | ||
LicenseModel(name: PlistFiles.SwiftUIWorkaround.name, plist: PlistFiles.SwiftUIWorkaround.preferenceSpecifiers) | ||
] | ||
} | ||
|
||
final class Binding: ObservableObject { | ||
// NOP | ||
} | ||
} | ||
|
||
|
||
// MARK: - Private | ||
private extension LicenseViewModel { | ||
|
||
func bind(input: Input, output: Output, binding: Binding) { | ||
// 親孫でのbindを可能にする | ||
binding.objectWillChange | ||
.sink { [weak self] _ in | ||
self?.objectWillChange.send() | ||
} | ||
.store(in: &cancellables) | ||
} | ||
} | ||
|
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,30 @@ | ||
import SwiftUI | ||
|
||
// MARK: - Model | ||
final class LicenseModel { | ||
let name: String | ||
let description: String | ||
|
||
init( | ||
name: String, | ||
plist: [[String: Any]] | ||
) { | ||
self.name = name.replaceExtension | ||
self.description = plist.compactMap { | ||
$0["FooterText"] as? String | ||
}.first ?? "" | ||
} | ||
} | ||
|
||
// MARK: - Identifiable | ||
extension LicenseModel: Identifiable { | ||
var id: UUID { UUID() } | ||
} | ||
|
||
/* fixme: いずれ stenceil ファイル側で制御する */ | ||
private extension String { | ||
|
||
var replaceExtension: String { | ||
replacingOccurrences(of: ".plist", with: "") | ||
} | ||
} |
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,23 @@ | ||
import SwiftUI | ||
|
||
// MARK: - Row | ||
struct LicenseRow<Destination: View>: View { | ||
let name: String | ||
let destination: Destination | ||
|
||
var body: some View { | ||
NavigationLink( | ||
destination: destination, | ||
label: { label } | ||
) | ||
} | ||
} | ||
|
||
// MARK: - Private | ||
private extension LicenseRow { | ||
|
||
var label: some View { | ||
Text(name) | ||
.foregroundColor(.primary) | ||
} | ||
} |
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,14 @@ | ||
import SwiftUI | ||
|
||
// MARK: - View | ||
struct LicenseDetailView: View { | ||
@ObservedObject var viewModel: LicenseDetailViewModel | ||
|
||
var body: some View { | ||
ScrollView { | ||
Text(viewModel.output.model.description) | ||
.padding() | ||
} | ||
.navigationBarTitle(viewModel.output.model.name, displayMode: .inline) | ||
} | ||
} |
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,43 @@ | ||
import SwiftUI | ||
import Foundation | ||
import Combine | ||
import CombineStorable | ||
|
||
|
||
// MARK: - ViewModel | ||
final class LicenseDetailViewModel: NSObject, ObservableObject, Storable { | ||
let input: Input | ||
let output: Output | ||
@ObservedObject var binding: Binding | ||
|
||
init( | ||
input: Input = .init(), | ||
output: Output = .init(), | ||
binding: Binding = .init() | ||
) { | ||
self.input = input | ||
self.output = output | ||
self.binding = binding | ||
super.init() | ||
} | ||
} | ||
|
||
// MARK: - Property | ||
extension LicenseDetailViewModel { | ||
|
||
final class Input { | ||
// NOP | ||
} | ||
|
||
final class Output: ObservableObject { | ||
let model: LicenseModel | ||
|
||
init(model: LicenseModel = .init(name: "", plist: [])) { | ||
self.model = model | ||
} | ||
} | ||
|
||
final class Binding: ObservableObject { | ||
// NOP | ||
} | ||
} |
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