[ABANDONED] Mastodon iOS client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.1 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // AttachmentPageViewController.swift
  3. // elpha-ios
  4. //
  5. // Created by Dwayne Harris on 11/1/18.
  6. // Copyright © 2018 Elpha. All rights reserved.
  7. //
  8. import UIKit
  9. class AttachmentPageViewController: UIPageViewController {
  10. var status: StatusMO?
  11. var controllers: [UIViewController] = []
  12. var attachmentIndex = 0
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. self.presentingViewController?.tabBarController?.tabBar.isHidden = true
  16. self.delegate = self
  17. self.dataSource = self
  18. if let status = status, let attachments = status.attachments {
  19. attachments.forEach { attachment in
  20. if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "AttachmentViewController") as? AttachmentViewController {
  21. controller.attachment = attachment as? AttachmentMO
  22. controllers.append(controller)
  23. }
  24. }
  25. }
  26. setViewControllers([controllers[attachmentIndex]], direction: .forward, animated: true, completion: nil)
  27. }
  28. func dismissController() {
  29. self.presentingViewController?.tabBarController?.tabBar.isHidden = false
  30. dismiss(animated: false)
  31. }
  32. override var preferredStatusBarStyle: UIStatusBarStyle {
  33. return .lightContent
  34. }
  35. override var prefersStatusBarHidden: Bool {
  36. return true
  37. }
  38. override func viewDidLayoutSubviews() {
  39. super.viewDidLayoutSubviews()
  40. for view in view.subviews {
  41. if view is UIScrollView {
  42. view.frame = UIScreen.main.bounds
  43. } else if view is UIPageControl {
  44. view.backgroundColor = UIColor.clear
  45. }
  46. }
  47. }
  48. }
  49. extension AttachmentPageViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate {
  50. func presentationCount(for pageViewController: UIPageViewController) -> Int {
  51. return controllers.count
  52. }
  53. func presentationIndex(for pageViewController: UIPageViewController) -> Int {
  54. return attachmentIndex
  55. }
  56. func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
  57. guard let index = controllers.index(of: viewController) else {
  58. return nil
  59. }
  60. if controllers.count == 1 {
  61. return nil
  62. }
  63. if index == 0 {
  64. return controllers.last
  65. }
  66. return controllers[index - 1]
  67. }
  68. func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
  69. guard let index = controllers.index(of: viewController) else {
  70. return nil
  71. }
  72. if controllers.count == 1 {
  73. return nil
  74. }
  75. if index == controllers.count - 1 {
  76. return controllers.first
  77. }
  78. return controllers[index + 1]
  79. }
  80. }