|
2 | 2 |
|
3 | 3 | All migration steps necessary in reading apps to upgrade to major versions of the Swift Readium toolkit will be documented in this file.
|
4 | 4 |
|
5 |
| -<!-- ## Unreleased --> |
| 5 | +## Unreleased |
| 6 | + |
| 7 | +### New Input API |
| 8 | + |
| 9 | +A new `InputObserving` API has been added to enable more flexible gesture recognition and support for mouse pointers. [See the dedicated user guide](Guides/Navigator/Input.md). |
| 10 | + |
| 11 | +The `DirectionalNavigationAdapter` was also updated to use this new API, and is easier to use. |
| 12 | + |
| 13 | +To migrate the old API, remove the old `VisualNavigatorDelegate` callbacks, for example: |
| 14 | + |
| 15 | +```diff |
| 16 | +-func navigator(_ navigator: VisualNavigator, didTapAt point: CGPoint) { |
| 17 | +- Task { |
| 18 | +- // Turn pages when tapping the edge of the screen. |
| 19 | +- guard await !DirectionalNavigationAdapter(navigator: navigator).didTap(at: point) else { |
| 20 | +- return |
| 21 | +- } |
| 22 | +- // clear a current search highlight |
| 23 | +- if let decorator = self.navigator as? DecorableNavigator { |
| 24 | +- decorator.apply(decorations: [], in: "search") |
| 25 | +- } |
| 26 | +- |
| 27 | +- toggleNavigationBar() |
| 28 | +- } |
| 29 | +-} |
| 30 | +- |
| 31 | +-func navigator(_ navigator: VisualNavigator, didPressKey event: KeyEvent) { |
| 32 | +- Task { |
| 33 | +- // Turn pages when pressing the arrow keys. |
| 34 | +- await DirectionalNavigationAdapter(navigator: navigator).didPressKey(event: event) |
| 35 | +- } |
| 36 | +-} |
| 37 | +``` |
| 38 | + |
| 39 | +Instead, setup your observers after initializing the navigator. Return `true` if you want to stop the propagation of a particular event to the next observers. |
| 40 | + |
| 41 | +```swift |
| 42 | +/// This adapter will automatically turn pages when the user taps the |
| 43 | +/// screen edges or press arrow keys. |
| 44 | +/// |
| 45 | +/// Bind it to the navigator before adding your own observers to prevent |
| 46 | +/// triggering your actions when turning pages. |
| 47 | +DirectionalNavigationAdapter().bind(to: navigator) |
| 48 | + |
| 49 | +// Clear the current search highlight on tap. |
| 50 | +navigator.addObserver(.tap { [weak self] _ in |
| 51 | + guard |
| 52 | + let searchViewModel = self?.searchViewModel, |
| 53 | + searchViewModel.selectedLocator != nil |
| 54 | + else { |
| 55 | + return false |
| 56 | + } |
| 57 | + |
| 58 | + searchViewModel.selectedLocator = nil |
| 59 | + return true |
| 60 | +}) |
| 61 | + |
| 62 | +// Toggle the navigation bar on tap, if nothing else took precedence. |
| 63 | +navigator.addObserver(.tap { [weak self] _ in |
| 64 | + self?.toggleNavigationBar() |
| 65 | + return true |
| 66 | +}) |
| 67 | +``` |
6 | 68 |
|
7 | 69 | ## 3.1.0
|
8 | 70 |
|
|
0 commit comments