From 83c156f9e645391a1f82e5601015bf3d9ab6245a Mon Sep 17 00:00:00 2001
From: Michael Kirk <michael@signal.org>
Date: Tue, 27 Nov 2018 13:54:38 -0700
Subject: [PATCH 1/3] Scroll photo-picker to bottom

---
 .../PhotoLibrary/ImagePickerController.swift  | 31 +++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift
index f8cd2061f..d4393a5d2 100644
--- a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift
+++ b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift
@@ -113,6 +113,37 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
         photoMediaSize.thumbnailSize = CGSize(width: cellSize.width * scale, height: cellSize.height * scale)
 
         reloadDataAndRestoreSelection()
+        scrollToBottom(animated: false)
+    }
+
+    override func viewDidAppear(_ animated: Bool) {
+        super.viewDidAppear(animated)
+    }
+
+    // MARK: 
+
+    func scrollToBottom(animated: Bool) {
+        self.view.layoutIfNeeded()
+
+        guard let collectionView = collectionView else {
+            owsFailDebug("collectionView was unexpectedly nil")
+            return
+        }
+
+        // We could try to be more precise by doing something like
+        //
+        //      let botomOffset = collectionView.contentSize + collectionView.contentInset.top - collectionView.bounds.height
+        //
+        // But `collectionView.contentInset` is based on `safeAreaInsets`, which isn't accurate
+        // until `viewDidAppear` at the earliest.
+        //
+        // from https://developer.apple.com/documentation/uikit/uiview/positioning_content_relative_to_the_safe_area
+        // > Make your modifications in [viewDidAppear] because the safe area insets for a view are
+        // > not accurate until the view is added to a view hierarchy.
+        //
+        // Overshooting like this works without visible animation glitch.
+        let bottomOffset = CGFloat.greatestFiniteMagnitude
+        collectionView.setContentOffset(CGPoint(x: 0, y: bottomOffset), animated: animated)
     }
 
     private func reloadDataAndRestoreSelection() {

From 1a43498c2e9422431c00777c1549a4d1d4d61e51 Mon Sep 17 00:00:00 2001
From: Michael Kirk <michael@signal.org>
Date: Tue, 27 Nov 2018 13:58:27 -0700
Subject: [PATCH 2/3] update masks for "always dark" media views

---
 Signal/src/views/PhotoGridViewCell.swift | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Signal/src/views/PhotoGridViewCell.swift b/Signal/src/views/PhotoGridViewCell.swift
index fdc486914..d7faa0762 100644
--- a/Signal/src/views/PhotoGridViewCell.swift
+++ b/Signal/src/views/PhotoGridViewCell.swift
@@ -57,12 +57,12 @@ public class PhotoGridViewCell: UICollectionViewCell {
 
         self.highlightedView = UIView()
         highlightedView.alpha = 0.2
-        highlightedView.backgroundColor = Theme.primaryColor
+        highlightedView.backgroundColor = Theme.darkThemePrimaryColor
         highlightedView.isHidden = true
 
         self.selectedView = UIView()
         selectedView.alpha = 0.3
-        selectedView.backgroundColor = Theme.backgroundColor
+        selectedView.backgroundColor = Theme.darkThemeBackgroundColor
         selectedView.isHidden = true
 
         super.init(frame: frame)

From 69e8b187adf69c27fae959c5abe01ba77be7525f Mon Sep 17 00:00:00 2001
From: Michael Kirk <michael@signal.org>
Date: Tue, 27 Nov 2018 15:39:04 -0700
Subject: [PATCH 3/3] only scroll down once

---
 .../PhotoLibrary/ImagePickerController.swift                | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift
index d4393a5d2..df01402df 100644
--- a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift
+++ b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift
@@ -98,6 +98,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
         updateLayout()
     }
 
+    var hasEverAppeared: Bool = false
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
 
@@ -113,7 +114,10 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
         photoMediaSize.thumbnailSize = CGSize(width: cellSize.width * scale, height: cellSize.height * scale)
 
         reloadDataAndRestoreSelection()
-        scrollToBottom(animated: false)
+        if !hasEverAppeared {
+            hasEverAppeared = true
+            scrollToBottom(animated: false)
+        }
     }
 
     override func viewDidAppear(_ animated: Bool) {