-
Notifications
You must be signed in to change notification settings - Fork 0
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 #7 from p-larson/mac-pagination
Pagination
- Loading branch information
Showing
8 changed files
with
211 additions
and
177 deletions.
There are no files selected for viewing
Binary file modified
BIN
+11.3 KB
(110%)
...odeproj/project.xcworkspace/xcuserdata/plarson.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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
73 changes: 73 additions & 0 deletions
73
BibleCore/Sources/ReaderCore/MobileReader/MobileReader.swift
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,73 @@ | ||
import BibleClient | ||
import BibleCore | ||
import CasePaths | ||
import SwiftUI | ||
import ComposableArchitecture | ||
import DirectoryCore | ||
|
||
public struct MobileReader: Reducer { | ||
public init() { | ||
// :) | ||
} | ||
|
||
public struct State: Equatable { | ||
var page = Page.State() | ||
var menuDirectory: MenuDirectory.State = MenuDirectory.State( | ||
isDirectoryOpen: true, | ||
books: [] | ||
) | ||
|
||
@BindingState public var isDirectoryOpen: Bool = false | ||
|
||
public init( | ||
isDirectoryOpen: Bool = false | ||
) { | ||
self.isDirectoryOpen = isDirectoryOpen | ||
} | ||
|
||
var contentName: String? { | ||
guard let book = page.book else { | ||
return nil | ||
} | ||
|
||
guard let chapter = page.chapter else { | ||
return book.name | ||
} | ||
|
||
return book.name + " " + chapter.id.description | ||
} | ||
} | ||
|
||
public enum Action: BindableAction, Equatable { | ||
case binding(_ action: BindingAction<State>) | ||
case openDirectory | ||
case page(Page.Action) | ||
case menuDirectory(MenuDirectory.Action) | ||
} | ||
|
||
public var body: some Reducer<State, Action> { | ||
BindingReducer() | ||
Scope(state: \.menuDirectory, action: /Action.menuDirectory) { | ||
MenuDirectory() | ||
} | ||
Scope(state: \.page, action: /Action.page) { | ||
Page() | ||
} | ||
Reduce<State, Action> { state, action in | ||
switch action { | ||
case .openDirectory: | ||
state.isDirectoryOpen = true | ||
return .none | ||
case .menuDirectory(.book(id: _, action: .select(let book, let chapter, let verses, let verse))): | ||
state.isDirectoryOpen = false | ||
return .send(.page(.open(book, chapter, verses, focused: verse, save: true))) | ||
case .menuDirectory: | ||
return .none | ||
case .page: | ||
return .none | ||
case .binding(_): | ||
return .none | ||
} | ||
} | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
BibleCore/Sources/ReaderCore/MobileReader/MobileReaderView.swift
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,109 @@ | ||
import ComposableArchitecture | ||
import DirectoryCore | ||
import SwiftUI | ||
|
||
public struct MobileReaderView: View { | ||
let store: StoreOf<MobileReader> | ||
|
||
public init(store: StoreOf<MobileReader>) { | ||
self.store = store | ||
} | ||
|
||
func arrows(_ viewStore: ViewStoreOf<MobileReader>) -> some View { | ||
HStack { | ||
Button { | ||
viewStore.send(.page(.paginateChapter(forward: false))) | ||
} label: { | ||
Image(systemName: "arrow.left") | ||
} | ||
Spacer() | ||
Button { | ||
viewStore.send(.page(.paginateChapter(forward: true))) | ||
} label: { | ||
Image(systemName: "arrow.right") | ||
} | ||
} | ||
.shadow(radius: 8) | ||
.buttonStyle(.borderedProminent) | ||
.padding() | ||
} | ||
|
||
public var body: some View { | ||
WithViewStore(store, observe: { $0 }) { viewStore in | ||
VStack { | ||
HStack { | ||
Button { | ||
viewStore.send(.openDirectory) | ||
} label: { | ||
if let book = viewStore.contentName { | ||
Text(book) | ||
} else { | ||
ProgressView() | ||
.progressViewStyle(.circular) | ||
.controlSize(.mini) | ||
} | ||
} | ||
.buttonStyle(.bordered) | ||
Spacer() | ||
} | ||
.padding(.horizontal) | ||
PageView( | ||
store: store.scope( | ||
state: \.page, | ||
action: MobileReader.Action.page | ||
) | ||
) | ||
} | ||
.overlay( | ||
HStack { | ||
Button { | ||
viewStore.send(.page(.paginateChapter(forward: false))) | ||
} label: { | ||
Image(systemName: "arrow.left") | ||
} | ||
Spacer() | ||
Button { | ||
viewStore.send(.page(.paginateChapter(forward: true))) | ||
} label: { | ||
Image(systemName: "arrow.right") | ||
} | ||
} | ||
.shadow(radius: 8) | ||
.buttonStyle(.borderedProminent) | ||
.padding() | ||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom) | ||
) | ||
.popover(isPresented: viewStore.$isDirectoryOpen) { | ||
NavigationStack { | ||
MenuDirectoryView( | ||
store: store.scope( | ||
state: \.menuDirectory, | ||
action: MobileReader.Action.menuDirectory | ||
) | ||
) | ||
.navigationTitle("Books") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension MobileReader.State { | ||
static let mock = MobileReader.State( | ||
isDirectoryOpen: false | ||
) | ||
} | ||
|
||
struct BookReaderView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
MobileReaderView( | ||
store: Store( | ||
initialState: .mock | ||
) { | ||
MobileReader() | ||
} | ||
) | ||
.previewDisplayName("Mobile") | ||
.previewDevice("iPhone 14") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.