Skip to content

Commit

Permalink
Improved bottom bar scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
Vince14Genius committed May 12, 2020
1 parent c24c634 commit 93418d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions IPA Keyboard Extension/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,21 @@ class KeyboardViewController: MasterKeyboardViewController, UICollectionViewData
UISelectionFeedbackGenerator().selectionChanged()
guard let buttonTitle = button.currentTitle else { fatalError("Wrong button.") }
for i in 0..<IPASymbols.sectionGlyphs.count {
let middleIndex = (getKeySet(section: i)?.count ?? 0) / 2
if buttonTitle == IPASymbols.sectionGlyphs[i] {
self.keyCollection.scrollToItem(at: [i, middleIndex], at: .centeredHorizontally, animated: true)
// Calculate middle index
let middleIndex = (getKeySet(section: i)?.count ?? 0) / 2

// Calculate columns on screen
let visibleItemsCount = self.keyCollection.indexPathsForVisibleItems.count

if middleIndex > visibleItemsCount / 2 + cellsPerColumn {
// big section
self.keyCollection.scrollToItem(at: [i, visibleItemsCount / 2 - cellsPerColumn], at: .centeredHorizontally, animated: true)
} else {
// small section
self.keyCollection.scrollToItem(at: [i, middleIndex], at: .centeredHorizontally, animated: true)
}

return
}
}
Expand Down
Binary file not shown.

0 comments on commit 93418d8

Please sign in to comment.