mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-01-18 06:56:48 +01:00
Xcode 11 beta 6
This commit is contained in:
@@ -10,7 +10,7 @@ import Foundation
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
final class GameLogic : BindableObject {
|
||||
final class GameLogic : ObservableObject {
|
||||
|
||||
enum Direction {
|
||||
case left
|
||||
@@ -21,7 +21,7 @@ final class GameLogic : BindableObject {
|
||||
|
||||
typealias BlockMatrixType = BlockMatrix<IdentifiedBlock>
|
||||
|
||||
let willChange = PassthroughSubject<GameLogic, Never>()
|
||||
let objectWillChange = PassthroughSubject<GameLogic, Never>()
|
||||
|
||||
fileprivate var _blockMatrix: BlockMatrixType!
|
||||
var blockMatrix: BlockMatrixType {
|
||||
@@ -42,12 +42,12 @@ final class GameLogic : BindableObject {
|
||||
_blockMatrix = BlockMatrixType()
|
||||
generateNewBlocks()
|
||||
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
|
||||
func move(_ direction: Direction) {
|
||||
defer {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
|
||||
var moved = false
|
||||
@@ -136,7 +136,7 @@ final class GameLogic : BindableObject {
|
||||
|
||||
// Don't forget to sync data.
|
||||
defer {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
|
||||
// Place the first block.
|
||||
|
||||
@@ -77,7 +77,7 @@ struct BlockGridView : View {
|
||||
y: CGFloat(block.index.1) * (65 + 12) + 32.5 + 12)
|
||||
.zIndex(self.zIndex(block.item))
|
||||
.transition(.blockAppear(from: self.blockEnterEdge))
|
||||
.animation(block.item == nil ? nil : .spring(mass: 1, stiffness: 400, damping: 56, initialVelocity: 0))
|
||||
// .animation(block.item == nil ? nil : .spring(mass: 1, stiffness: 400, damping: 56, initialVelocity: 0))
|
||||
}
|
||||
}
|
||||
.frame(width: 320, height: 320, alignment: .center)
|
||||
|
||||
@@ -8,18 +8,18 @@ A model object that stores app data.
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
final class UserData: BindableObject {
|
||||
let willChange = PassthroughSubject<UserData, Never>()
|
||||
final class UserData: ObservableObject {
|
||||
let objectWillChange = PassthroughSubject<UserData, Never>()
|
||||
|
||||
var showFavoritesOnly = false {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
var landmarks = landmarkData {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ struct Calculator: View {
|
||||
.foregroundColor(Color.blue)
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
||||
.background(Color(red: 234 / 255.0, green: 240 / 255.0, blue: 241 / 255.0))
|
||||
.tapAction {
|
||||
.onTapGesture {
|
||||
self.touchAction(item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ struct SearchUserView: View {
|
||||
|
||||
List(viewModel.users) { user in
|
||||
SearchUserRow(user: user)
|
||||
.tapAction { print(user) }
|
||||
.onTapGesture { print(user) }
|
||||
}
|
||||
}
|
||||
.navigationBarTitle(Text("Users"))
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
final class SearchUserViewModel: BindableObject {
|
||||
var willChange = PassthroughSubject<SearchUserViewModel, Never>()
|
||||
final class SearchUserViewModel: ObservableObject {
|
||||
var objectWillChange = PassthroughSubject<SearchUserViewModel, Never>()
|
||||
|
||||
private(set) var users = [User]() {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
private(set) var userImages = [User: UIImage]() {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,18 +8,18 @@ A model object that stores app data.
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
final class UserData: BindableObject {
|
||||
let willChange = PassthroughSubject<UserData, Never>()
|
||||
final class UserData: ObservableObject {
|
||||
let objectWillChange = PassthroughSubject<UserData, Never>()
|
||||
|
||||
var showFavoritesOnly = false {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
var landmarks = landmarkData {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ struct ConverterView : View {
|
||||
|
||||
var body: some View {
|
||||
let inset = EdgeInsets(top: -8, leading: -20, bottom: -7, trailing: 5)
|
||||
let doubleValue: Double = Double(self.$baseAmount.value) ?? 1.0
|
||||
let doubleValue: Double = Double(self.$baseAmount.wrappedValue) ?? 1.0
|
||||
|
||||
return ZStack(alignment: Alignment.bottomTrailing) {
|
||||
NavigationView {
|
||||
@@ -56,7 +56,7 @@ struct ConverterView : View {
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 5)
|
||||
.fill(Color.clear)
|
||||
.border(Color(red: 0.7, green: 0.7, blue: 0.7), width: 1 / UIScreen.main.scale, cornerRadius: 5)
|
||||
.background(RoundedRectangle(cornerRadius: 5).strokeBorder(Color(red: 0.7, green: 0.7, blue: 0.7), lineWidth: 1 / UIScreen.main.scale))
|
||||
.padding(inset)
|
||||
)
|
||||
}.background(Color.blue).cornerRadius(5)
|
||||
@@ -64,7 +64,7 @@ struct ConverterView : View {
|
||||
List {
|
||||
// TODO: should filter out BaseCurrency from list
|
||||
ForEach(userData.userCurrency) { currency in
|
||||
CurrencyItemView(currency: currency, baseAmount: doubleValue, isEditing: self.$isEditing).tapAction {
|
||||
CurrencyItemView(currency: currency, baseAmount: doubleValue, isEditing: self.$isEditing).onTapGesture {
|
||||
// Swap this and base
|
||||
self.userData.baseCurrency = currency
|
||||
}
|
||||
@@ -89,7 +89,7 @@ struct ConverterView : View {
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 23)
|
||||
.fill(Color.blue)
|
||||
.border(Color(red: 0.7, green: 0.7, blue: 0.7), width: 1 / UIScreen.main.scale, cornerRadius: 23))
|
||||
.background(RoundedRectangle(cornerRadius: 23).strokeBorder(Color(red: 0.7, green: 0.7, blue: 0.7), lineWidth: 1 / UIScreen.main.scale)))
|
||||
.foregroundColor(.white).font(.largeTitle)
|
||||
}.padding()
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ struct CurrencyItemView: View {
|
||||
HStack(alignment: .center){
|
||||
Image(systemName: "minus.circle")
|
||||
.foregroundColor(.red)
|
||||
.tapAction(count: 1) {
|
||||
.onTapGesture(count: 1) {
|
||||
self.delete()
|
||||
}
|
||||
|
||||
|
||||
@@ -51,27 +51,27 @@ struct UserDefaultValue<Value: Codable> {
|
||||
}
|
||||
}
|
||||
|
||||
final class UserData: BindableObject {
|
||||
let willChange = PassthroughSubject<UserData, Never>()
|
||||
final class UserData: ObservableObject {
|
||||
let objectWillChange = PassthroughSubject<UserData, Never>()
|
||||
|
||||
@UserDefaultValue(key: "allCurrencies", defaultValue: defaultCurrencies)
|
||||
var allCurrencies: [Currency] {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
@UserDefaultValue(key: "baseCurrency", defaultValue: defaultCurrencies[0])
|
||||
var baseCurrency: Currency {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
@UserDefaultValue(key: "userCurrency", defaultValue: defaultCurrencies)
|
||||
var userCurrency: [Currency] {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,18 +8,18 @@ A model object that stores app data.
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
final class UserData: BindableObject {
|
||||
let willChange = PassthroughSubject<UserData, Never>()
|
||||
final class UserData: ObservableObject {
|
||||
let objectWillChange = PassthroughSubject<UserData, Never>()
|
||||
|
||||
var showFavoritesOnly = false {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
var landmarks = landmarkData {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ struct TaskEditView: View {
|
||||
let inset = EdgeInsets(top: -8, leading: -10, bottom: -7, trailing: -10)
|
||||
return VStack(alignment: .leading, spacing: 0) {
|
||||
TextField(
|
||||
"Enter New Title...", text: self.draftTitle.binding,
|
||||
"Enter New Title...", text: self.draftTitle.projectedValue,
|
||||
onEditingChanged: { _ in self.updateTask() },
|
||||
onCommit: {}
|
||||
)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 5)
|
||||
.fill(Color.clear)
|
||||
.border(Color(red: 0.7, green: 0.7, blue: 0.7), width: 1 / UIScreen.main.scale, cornerRadius: 5)
|
||||
.background(RoundedRectangle(cornerRadius: 5).strokeBorder(Color(red: 0.7, green: 0.7, blue: 0.7), lineWidth: 1 / UIScreen.main.scale))
|
||||
.padding(inset)
|
||||
)
|
||||
.padding(EdgeInsets(
|
||||
@@ -46,6 +46,6 @@ struct TaskEditView: View {
|
||||
|
||||
private func updateTask() {
|
||||
guard let index = self.userData.tasks.firstIndex(of: self.task) else { return }
|
||||
self.userData.tasks[index].title = self.draftTitle.value
|
||||
self.userData.tasks[index].title = self.draftTitle.wrappedValue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ struct TaskItemView: View {
|
||||
if self.isEditing {
|
||||
Image(systemName: "minus.circle")
|
||||
.foregroundColor(.red)
|
||||
.tapAction(count: 1) {
|
||||
.onTapGesture(count: 1) {
|
||||
self.delete()
|
||||
}
|
||||
NavigationLink(destination: TaskEditView(task: task).environmentObject(self.userData)) {
|
||||
|
||||
@@ -14,13 +14,13 @@ private let defaultTasks: [Task] = [
|
||||
Task(title: "Watch WWDC19 Keynote 🎉", isDone: true),
|
||||
]
|
||||
|
||||
final class UserData: BindableObject {
|
||||
let willChange = PassthroughSubject<UserData, Never>()
|
||||
final class UserData: ObservableObject {
|
||||
let objectWillChange = PassthroughSubject<UserData, Never>()
|
||||
|
||||
@UserDefaultValue(key: "Tasks", defaultValue: defaultTasks)
|
||||
var tasks: [Task] {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
final class Store<State, Action>: BindableObject {
|
||||
final class Store<State, Action>: ObservableObject {
|
||||
typealias Reducer = (State, Action) -> State
|
||||
|
||||
let willChange = PassthroughSubject<State, Never>()
|
||||
let objectWillChange = PassthroughSubject<State, Never>()
|
||||
|
||||
var state: State {
|
||||
lock.lock()
|
||||
@@ -29,6 +29,6 @@ final class Store<State, Action>: BindableObject {
|
||||
|
||||
lock.unlock()
|
||||
|
||||
willChange.send(newState)
|
||||
objectWillChange.send(newState)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,5 @@
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
extension JSONDecoder: TopLevelDecoder {}
|
||||
// now in Foundation
|
||||
//extension JSONDecoder: TopLevelDecoder {}
|
||||
|
||||
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
|
||||
struct RepositoryListView : View {
|
||||
|
||||
@ObjectBinding
|
||||
@ObservedObject
|
||||
private(set) var viewModel: RepositoryListViewModel
|
||||
|
||||
var body: some View {
|
||||
@@ -24,15 +24,15 @@ struct RepositoryListView : View {
|
||||
onCommit: { self.viewModel.search() })
|
||||
.frame(height: 40)
|
||||
.padding(EdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 8))
|
||||
.border(Color.gray, cornerRadius: 8)
|
||||
.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
|
||||
.background(RoundedRectangle(cornerRadius: 8).strokeBorder(Color.gray, lineWidth: 2))
|
||||
|
||||
Button(action: { self.viewModel.search() }) {
|
||||
Text("Search")
|
||||
}
|
||||
.frame(height: 40)
|
||||
.padding(EdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 8))
|
||||
.border(Color.blue, cornerRadius: 8)
|
||||
.background(RoundedRectangle(cornerRadius: 8).strokeBorder(Color.blue, lineWidth: 2))
|
||||
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 16))
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ import Combine
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
final class RepositoryListViewModel: BindableObject {
|
||||
final class RepositoryListViewModel: ObservableObject {
|
||||
typealias SearchRepositories = (String) -> AnyPublisher<Result<[Repository], ErrorResponse>, Never>
|
||||
|
||||
let willChange: AnyPublisher<RepositoryListViewModel, Never>
|
||||
let objectWillChange: AnyPublisher<RepositoryListViewModel, Never>
|
||||
private let _didChange = PassthroughSubject<RepositoryListViewModel, Never>()
|
||||
|
||||
private let _searchWithQuery = PassthroughSubject<String, Never>()
|
||||
@@ -34,7 +34,7 @@ final class RepositoryListViewModel: BindableObject {
|
||||
init<S: Scheduler>(searchRepositories: @escaping SearchRepositories = RepositoryAPI.search,
|
||||
mainScheduler: S) {
|
||||
|
||||
self.willChange = _didChange.eraseToAnyPublisher()
|
||||
self.objectWillChange = _didChange.eraseToAnyPublisher()
|
||||
|
||||
let response = _searchWithQuery
|
||||
.filter { !$0.isEmpty }
|
||||
|
||||
@@ -8,18 +8,18 @@ A model object that stores app data.
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
final class UserData: BindableObject {
|
||||
let willChange = PassthroughSubject<UserData, Never>()
|
||||
final class UserData: ObservableObject {
|
||||
let objectWillChange = PassthroughSubject<UserData, Never>()
|
||||
|
||||
var showFavoritesOnly = false {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
var landmarks = landmarkData {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,10 @@ struct HikeBadge: View {
|
||||
var name: String
|
||||
var body: some View {
|
||||
VStack(alignment: .center) {
|
||||
// crashes in Beta 5
|
||||
// Badge()
|
||||
// .frame(width: 300, height: 300)
|
||||
// .scaleEffect(1.0 / 3.0)
|
||||
// .frame(width: 100, height: 100)
|
||||
Badge()
|
||||
.frame(width: 300, height: 300)
|
||||
.scaleEffect(1.0 / 3.0)
|
||||
.frame(width: 100, height: 100)
|
||||
Text(name)
|
||||
.font(.caption)
|
||||
.accessibility(label: Text("Badge for \(name)."))
|
||||
|
||||
@@ -8,18 +8,18 @@ A model object that stores app data.
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
final class UserData: BindableObject {
|
||||
let willChange = PassthroughSubject<UserData, Never>()
|
||||
final class UserData: ObservableObject {
|
||||
let objectWillChange = PassthroughSubject<UserData, Never>()
|
||||
|
||||
var showFavoritesOnly = false {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
var landmarks = landmarkData {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ struct ProfileHost: View {
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 20) {
|
||||
HStack {
|
||||
if self.mode?.value == .active {
|
||||
if self.mode?.wrappedValue == .active {
|
||||
Button(action: {
|
||||
self.draftProfile = self.profile
|
||||
self.mode?.animation().value = .inactive
|
||||
self.mode?.animation().wrappedValue = .inactive
|
||||
}) {
|
||||
Text("Done")
|
||||
}
|
||||
@@ -28,7 +28,7 @@ struct ProfileHost: View {
|
||||
|
||||
EditButton()
|
||||
}
|
||||
if self.mode?.value == .inactive {
|
||||
if self.mode?.wrappedValue == .inactive {
|
||||
ProfileSummary(profile: profile)
|
||||
} else {
|
||||
ProfileEditor(profile: $draftProfile)
|
||||
|
||||
@@ -31,7 +31,7 @@ struct CategoryItem: View {
|
||||
VStack{
|
||||
Color.white
|
||||
.frame(width:65,height:65)
|
||||
.border(Color(red: 218.0/255.0, green: 218.0/255.0, blue: 218.0/255.0),width: 3,cornerRadius: 15)
|
||||
.background(RoundedRectangle(cornerRadius: 15).strokeBorder(Color(red: 218.0/255.0, green: 218.0/255.0, blue: 218.0/255.0), lineWidth: 3))
|
||||
.cornerRadius(15)
|
||||
zone
|
||||
.image(forSize: 55)
|
||||
|
||||
@@ -10,8 +10,8 @@ import Foundation
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
final class AppState: BindableObject {
|
||||
var willChange = PassthroughSubject<AppState, Never>()
|
||||
final class AppState: ObservableObject {
|
||||
var objectWillChange = PassthroughSubject<AppState, Never>()
|
||||
|
||||
var moviesState: MoviesState
|
||||
|
||||
@@ -22,7 +22,7 @@ final class AppState: BindableObject {
|
||||
func dispatch(action: Action) {
|
||||
moviesState = MoviesStateReducer().reduce(state: moviesState, action: action)
|
||||
DispatchQueue.main.async {
|
||||
self.willChange.send(self)
|
||||
self.objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import Foundation
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
final class AppState: BindableObject {
|
||||
var willChange = PassthroughSubject<AppState, Never>()
|
||||
final class AppState: ObservableObject {
|
||||
var objectWillChange = PassthroughSubject<AppState, Never>()
|
||||
|
||||
var usersState: UsersState
|
||||
|
||||
@@ -21,7 +21,7 @@ final class AppState: BindableObject {
|
||||
|
||||
func dispatch(action: Action) {
|
||||
usersState = UserStateReducer().reduce(state: usersState, action: action)
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ struct TabbarView : View {
|
||||
@State var selectedIndex: Int = 0
|
||||
|
||||
var body: some View {
|
||||
TabbedView(selection: $selectedIndex) {
|
||||
TabView(selection: $selectedIndex) {
|
||||
UsersListView()
|
||||
.tabItem({ Text("Users") })
|
||||
MapView()
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("User name")
|
||||
TextField("New name", text: $newUserName)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
Divider()
|
||||
Text("Username")
|
||||
TextField("New username", text: $newUserUsername)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
}.padding(16)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
}.padding(16)
|
||||
Button(action: save) {
|
||||
Text("Save")
|
||||
.padding(8)
|
||||
@@ -42,7 +42,7 @@
|
||||
Text("Close")
|
||||
})
|
||||
.navigationBarTitle(Text("Edit \(user.name)"), displayMode: .inline)
|
||||
|
||||
|
||||
Badge(text: "Saved successfully", color: .green, show: $showSaved)
|
||||
Badge(text: "Missing username or name", color: .red, show: $showError)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ struct UsersListView : View {
|
||||
.onMove(perform: move)
|
||||
}
|
||||
}
|
||||
.listStyle(.grouped)
|
||||
.listStyle(GroupedListStyle())
|
||||
.navigationBarTitle(Text("Users (\(state.usersState.users.count))"))
|
||||
.navigationBarItems(trailing: EditButton())
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
public final class Store<StateType>: BindableObject where StateType: StateMachine {
|
||||
public final class Store<StateType>: ObservableObject where StateType: StateMachine {
|
||||
|
||||
private let initialState: StateType
|
||||
private var subsequentStates: [StateType] = []
|
||||
|
||||
public let willChange = PassthroughSubject<Void, Never>()
|
||||
public let objectWillChange = PassthroughSubject<Void, Never>()
|
||||
|
||||
public init(state: StateType) {
|
||||
initialState = state
|
||||
@@ -23,7 +23,7 @@ public final class Store<StateType>: BindableObject where StateType: StateMachin
|
||||
var currentStateIndex: Int = 0 {
|
||||
didSet {
|
||||
withAnimation {
|
||||
willChange.send(())
|
||||
objectWillChange.send(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ struct TimeTravelBarView : View {
|
||||
@EnvironmentObject var store: Store<TodoState>
|
||||
|
||||
var body: some View {
|
||||
let indexBinding = Binding<Double>(
|
||||
getValue: { Double(self.store.currentStateIndex) },
|
||||
setValue: { self.store.currentStateIndex = Int($0) })
|
||||
let indexBinding = Binding(
|
||||
get: { Double(self.store.currentStateIndex) },
|
||||
set: { self.store.currentStateIndex = Int($0) })
|
||||
|
||||
return Slider(value: indexBinding, in: 0...Double(store.stateCount-1))
|
||||
.background(Color.white)
|
||||
|
||||
@@ -6,9 +6,9 @@ struct AddItemView: View {
|
||||
|
||||
var body: some View {
|
||||
|
||||
let textBinding = Binding<String>(
|
||||
getValue: { self.store.state.partialItemName },
|
||||
setValue: { self.store.dispatch(event: .changePartialItemName($0)) })
|
||||
let textBinding = Binding(
|
||||
get: { self.store.state.partialItemName },
|
||||
set: { self.store.dispatch(event: .changePartialItemName($0)) })
|
||||
|
||||
return VStack(spacing: 16) {
|
||||
TextField("Title", text: textBinding)
|
||||
|
||||
@@ -12,7 +12,7 @@ struct ModalDimmingView : View {
|
||||
.opacity(0.3)
|
||||
.edgesIgnoringSafeArea([.bottom, .top])
|
||||
.transition(.opacity)
|
||||
.tapAction {
|
||||
.onTapGesture {
|
||||
self.store.dispatch(event: .cancelCreatingItem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
final class UserData: BindableObject {
|
||||
let willChange = PassthroughSubject<UserData, Never>()
|
||||
final class UserData: ObservableObject {
|
||||
let objectWillChange = PassthroughSubject<UserData, Never>()
|
||||
|
||||
var notes = NoteData.shared.notes {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
NoteData.shared.notes = notes
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ struct NoteDetail : View {
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
TextField("", text: self.text.binding,
|
||||
TextField("", text: self.text.projectedValue,
|
||||
onEditingChanged: { _ in self.updateNote()},
|
||||
onCommit: {})
|
||||
Spacer()
|
||||
@@ -35,7 +35,7 @@ struct NoteDetail : View {
|
||||
}
|
||||
|
||||
private func updateNote() {
|
||||
self.userData.notes[noteIndex].text = self.text.value
|
||||
self.userData.notes[noteIndex].text = self.text.wrappedValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,6 @@ struct VideoListView : View {
|
||||
}
|
||||
}
|
||||
}
|
||||
}.listStyle(.grouped)
|
||||
}.listStyle(GroupedListStyle())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,24 +8,24 @@
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
final class UserData: BindableObject {
|
||||
let willChange = PassthroughSubject<UserData, Never>()
|
||||
final class UserData: ObservableObject {
|
||||
let objectWillChange = PassthroughSubject<UserData, Never>()
|
||||
|
||||
var showFavoriteOnly = false {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
var videos = videoList {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
var currentVideo = videoList[0] {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ struct VideoRow : View {
|
||||
|
||||
Image(systemName: video.isFavorite ? "star.fill" : "star")
|
||||
.foregroundColor(video.isFavorite ? Color.yellow : Color.gray)
|
||||
.tapAction {
|
||||
.onTapGesture {
|
||||
self.setFavorite(video: self.video)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding([.top, .bottom], 10)
|
||||
.tapAction {
|
||||
.onTapGesture {
|
||||
self.setCurrentVideo(video: self.video)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,10 @@ struct HikeBadge: View {
|
||||
var name: String
|
||||
var body: some View {
|
||||
VStack(alignment: .center) {
|
||||
// crashes in Beta 5
|
||||
// Badge()
|
||||
// .frame(width: 300, height: 300)
|
||||
// .scaleEffect(1.0 / 3.0)
|
||||
// .frame(width: 100, height: 100)
|
||||
Badge()
|
||||
.frame(width: 300, height: 300)
|
||||
.scaleEffect(1.0 / 3.0)
|
||||
.frame(width: 100, height: 100)
|
||||
Text(name)
|
||||
.font(.caption)
|
||||
.accessibility(label: Text("Badge for \(name)."))
|
||||
|
||||
@@ -8,19 +8,19 @@ A model object that stores app data.
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
final class UserData: BindableObject {
|
||||
final class UserData: ObservableObject {
|
||||
|
||||
let willChange = PassthroughSubject<UserData, Never>()
|
||||
let objectWillChange = PassthroughSubject<UserData, Never>()
|
||||
|
||||
var showFavoritesOnly = false {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
var landmarks = landmarkData {
|
||||
didSet {
|
||||
willChange.send(self)
|
||||
objectWillChange.send(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ struct ProfileHost: View {
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 20) {
|
||||
HStack {
|
||||
if self.mode?.value == .active {
|
||||
if self.mode?.wrappedValue == .active {
|
||||
Button(action: {
|
||||
self.draftProfile = self.profile
|
||||
self.mode?.animation().value = .inactive
|
||||
self.mode?.animation().wrappedValue = .inactive
|
||||
}) {
|
||||
Text("Done")
|
||||
}
|
||||
@@ -28,7 +28,7 @@ struct ProfileHost: View {
|
||||
|
||||
EditButton()
|
||||
}
|
||||
if self.mode?.value == .inactive {
|
||||
if self.mode?.wrappedValue == .inactive {
|
||||
ProfileSummary(profile: profile)
|
||||
} else {
|
||||
ProfileEditor(profile: $draftProfile)
|
||||
|
||||
Reference in New Issue
Block a user