Skip to content

Commit 8296bda

Browse files
authored
Fix recent album not showing count (#17498)
1 parent ca2b3ab commit 8296bda

File tree

11 files changed

+85
-29
lines changed

11 files changed

+85
-29
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
android:name=".MainApplication"
3434
android:largeHeap="true"
3535
android:usesCleartextTraffic="true"
36-
android:extractNativeLibs="true">
36+
android:extractNativeLibs="true"
37+
android:requestLegacyExternalStorage="true">
3738
<!-- After upgrading Android Gradle Plugin to 4.2.0 and above we must get rid of `extractNativeLibs="true"`
3839
and use`useLegacyPackaging` flag in our app's `build.gradle`-->
3940
<meta-data android:name="commitHash" android:value="${commitHash}"/>

ios/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ PODS:
247247
- React-Core
248248
- react-native-blur (4.3.3):
249249
- React-Core
250-
- react-native-cameraroll (4.0.4):
250+
- react-native-cameraroll (5.10.0):
251251
- React-Core
252252
- react-native-config (1.5.0):
253253
- react-native-config/App (= 1.5.0)
@@ -468,7 +468,7 @@ DEPENDENCIES:
468468
- react-native-background-timer (from `../node_modules/react-native-background-timer`)
469469
- react-native-blob-util (from `../node_modules/react-native-blob-util`)
470470
- "react-native-blur (from `../node_modules/@react-native-community/blur`)"
471-
- "react-native-cameraroll (from `../node_modules/@react-native-community/cameraroll`)"
471+
- "react-native-cameraroll (from `../node_modules/@react-native-camera-roll/camera-roll`)"
472472
- react-native-config (from `../node_modules/react-native-config`)
473473
- react-native-image-resizer (from `../node_modules/react-native-image-resizer`)
474474
- react-native-lottie-splash-screen (from `../node_modules/react-native-lottie-splash-screen`)
@@ -584,7 +584,7 @@ EXTERNAL SOURCES:
584584
react-native-blur:
585585
:path: "../node_modules/@react-native-community/blur"
586586
react-native-cameraroll:
587-
:path: "../node_modules/@react-native-community/cameraroll"
587+
:path: "../node_modules/@react-native-camera-roll/camera-roll"
588588
react-native-config:
589589
:path: "../node_modules/react-native-config"
590590
react-native-image-resizer:
@@ -723,7 +723,7 @@ SPEC CHECKSUMS:
723723
react-native-background-timer: 1f7d560647b40e6a60b01c452ba29c54bf581fc4
724724
react-native-blob-util: 600972b1782380a5a7d5db61a3817ea32349dae9
725725
react-native-blur: c6d0a1dc2b4b519f7afe3b14d8151998632b6d18
726-
react-native-cameraroll: 88f4e62d9ecd0e1f253abe4f685474f2ea14bfa2
726+
react-native-cameraroll: 4701ae7c3dbcd3f5e9e150ca17f250a276154b35
727727
react-native-config: 5330c8258265c1e5fdb8c009d2cabd6badd96727
728728
react-native-image-resizer: 2f1577efa3bc762597681f530c8e8d05ce0ceeb3
729729
react-native-lottie-splash-screen: 068688c15dd478301fda00f8d87d7fb7d5b9a93e
@@ -777,6 +777,6 @@ SPEC CHECKSUMS:
777777
TouchID: ba4c656d849cceabc2e4eef722dea5e55959ecf4
778778
Yoga: d24d6184b6b85f742536bd93bd07d69d7b9bb4c1
779779

780-
PODFILE CHECKSUM: 259dd9b0a973943f02a5912c799a4db3ed475b66
780+
PODFILE CHECKSUM: 6a5f0e6776ce4ef6193032d077947117ace77a87
781781

782782
COCOAPODS: 1.12.0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"dependencies": {
1111
"@babel/preset-typescript": "^7.17.12",
1212
"@react-native-async-storage/async-storage": "^1.17.9",
13+
"@react-native-camera-roll/camera-roll": "git+https://github.com/status-im/react-native-camera-roll.git#refs/tags/v5.1.1.1",
1314
"@react-native-community/audio-toolkit": "git+https://github.com/tbenr/react-native-audio-toolkit.git#refs/tags/v2.0.3-status-v6",
1415
"@react-native-community/blur": "git+https://github.com/status-im/react-native-blur#refs/tags/v4.3.3-status",
15-
"@react-native-community/cameraroll": "git+https://github.com/status-im/react-native-cameraroll.git#refs/tags/v4.0.4-status.0",
1616
"@react-native-community/clipboard": "^1.2.2",
1717
"@react-native-community/hooks": "^3.0.0",
1818
"@react-native-community/masked-view": "^0.1.6",

package.json.gpg

-2.14 KB
Binary file not shown.

src/mocks/js_dependencies.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@
346346
(clj->js {:BlurView {}}))
347347

348348
(def react-native-camera-roll
349-
(clj->js {:default #js {}}))
349+
(clj->js {:default #js {}
350+
:CameraRoll #js {}}))
350351

351352
(def react-native-orientation-locker
352353
(clj->js {:default #js {}
@@ -410,7 +411,7 @@
410411
"react-native-navigation" react-native-navigation
411412
"@react-native-community/push-notification-ios" push-notification-ios
412413
"@react-native-community/blur" react-native-blur
413-
"@react-native-community/cameraroll" react-native-camera-roll
414+
"@react-native-camera-roll/camera-roll" react-native-camera-roll
414415
"react-native-camera-kit" react-native-camera-kit
415416
"react-native-permissions" react-native-permissions
416417
"rn-emoji-keyboard" rn-emoji-keyboard

src/react_native/cameraroll.cljs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns react-native.cameraroll
22
(:require
3-
["@react-native-community/cameraroll" :as CameraRoll]
3+
["@react-native-camera-roll/camera-roll" :refer [CameraRoll]]
44
[react-native.fs :as fs]
55
[taoensso.timbre :as log]
66
[utils.transforms :as transforms]))
@@ -22,3 +22,9 @@
2222
(-> (.save CameraRoll (clj->js path))
2323
(.then #(fs/unlink path))
2424
(.catch #(fs/unlink path))))
25+
26+
(defn get-photos-count-ios
27+
[cb]
28+
(-> (.getPhotosCountiOS CameraRoll)
29+
(.then #(cb %))
30+
(.catch #(js/console.error %))))

src/status_im2/contexts/chat/photo_selector/album_selector/view.cljs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[quo.foundations.colors :as colors]
55
[react-native.core :as rn]
66
[react-native.gesture :as gesture]
7+
[react-native.platform :as platform]
78
[react-native.reanimated :as reanimated]
89
[status-im2.contexts.chat.photo-selector.album-selector.style :as style]
910
[utils.i18n :as i18n]
@@ -61,15 +62,25 @@
6162

6263
(defn- f-album-selector
6364
[{:keys [scroll-enabled on-scroll]} album? selected-album top]
64-
(let [albums (rf/sub [:camera-roll/albums])
65-
albums-sections [{:title no-title :data (:smart-albums albums)}
66-
{:title (i18n/label :t/my-albums) :data (:my-albums albums)}]
67-
window-height (:height (rn/get-window))]
65+
(let [albums (rf/sub [:camera-roll/albums])
66+
total-photos-count-android (rf/sub [:camera-roll/total-photos-count-android])
67+
total-photos-count-ios (rf/sub [:camera-roll/total-photos-count-ios])
68+
albums-sections [{:title no-title
69+
:data [(assoc (:smart-album albums)
70+
:count
71+
(if platform/ios?
72+
total-photos-count-ios
73+
total-photos-count-android))]}
74+
{:title (i18n/label :t/my-albums)
75+
:data (:my-albums albums)}]
76+
window-height (:height (rn/get-window))]
6877
[reanimated/view {:style (style/selector-container top)}
6978
[gesture/section-list
7079
{:data albums-sections
7180
:sections albums-sections
72-
:render-data {:album? album? :selected-album selected-album :top top}
81+
:render-data {:album? album?
82+
:selected-album selected-album
83+
:top top}
7384
:render-fn render-album
7485
:sticky-section-headers-enabled false
7586
:render-section-header-fn section-header

src/status_im2/contexts/chat/photo_selector/events.cljs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[react-native.core :as rn]
77
[react-native.image-resizer :as image-resizer]
88
[react-native.permissions :as permissions]
9+
[react-native.platform :as platform]
910
[status-im2.constants :as constants]
1011
[taoensso.timbre :as log]
1112
[utils.i18n :as i18n]
@@ -56,25 +57,25 @@
5657

5758
(defn get-albums
5859
[callback]
59-
(let [albums (atom {:smart-albums []
60-
:my-albums []})]
60+
(let [albums (atom {:smart-album []
61+
:my-albums []})]
6162
;; Get the "recent" album first
6263
(cameraroll/get-photos
63-
{:first 1 :groupTypes "All"}
64+
{:first 1 :groupTypes "All" :assetType "Photos"}
6465
(fn [res-recent]
6566
(swap! albums assoc
66-
:smart-albums
67-
[{:title (i18n/label :t/recent)
68-
:uri (get-in (first (:edges res-recent)) [:node :image :uri])}])
67+
:smart-album
68+
{:title (i18n/label :t/recent)
69+
:uri (get-in (first (:edges res-recent)) [:node :image :uri])})
6970
;; Get albums, then loop over albums and get each one's cover (first photo)
7071
(cameraroll/get-albums
71-
{:assetType :Photos}
72+
{:assetType "Photos"}
7273
(fn [res-albums]
7374
(let [response-count (count res-albums)]
7475
(if (pos? response-count)
7576
(doseq [album res-albums]
7677
(cameraroll/get-photos
77-
{:first 1 :groupTypes "Albums" :groupName (:title album)}
78+
{:first 1 :groupTypes "Albums" :groupName (:title album) :assetType "Photos"}
7879
(fn [res]
7980
(let [uri (get-in (first (:edges res)) [:node :image :uri])]
8081
(swap! albums update :my-albums conj (merge album {:uri uri}))
@@ -83,21 +84,42 @@
8384
(callback @albums))))))
8485
(callback @albums)))))))))
8586

87+
(defn get-photos-count-ios-fx
88+
[cb]
89+
(cameraroll/get-photos-count-ios cb))
90+
8691
(re-frame/reg-fx
8792
:camera-roll-get-albums
8893
(fn []
8994
(get-albums #(re-frame/dispatch [:on-camera-roll-get-albums %]))))
9095

96+
(re-frame/reg-fx
97+
:camera-roll-get-photos-count-ios
98+
(fn []
99+
(when platform/ios?
100+
(get-photos-count-ios-fx #(re-frame/dispatch [:on-camera-roll-get-images-count-ios %])))))
101+
91102
(rf/defn on-camera-roll-get-albums
92103
{:events [:on-camera-roll-get-albums]}
93104
[{:keys [db]} albums]
94-
{:db (assoc db :camera-roll/albums albums)})
105+
{:db (assoc db :camera-roll/albums albums)
106+
:dispatch [:photo-selector/camera-roll-get-ios-photo-count]})
107+
108+
(rf/defn get-photos-count-ios
109+
{:events [:on-camera-roll-get-images-count-ios]}
110+
[{:keys [db]} count]
111+
{:db (assoc db :camera-roll/ios-images-count count)})
95112

96113
(rf/defn camera-roll-get-albums
97114
{:events [:photo-selector/camera-roll-get-albums]}
98115
[_]
99116
{:camera-roll-get-albums nil})
100117

118+
(rf/defn camera-roll-get-ios-photo-count
119+
{:events [:photo-selector/camera-roll-get-ios-photo-count]}
120+
[_]
121+
{:camera-roll-get-photos-count-ios nil})
122+
101123
(rf/defn camera-roll-select-album
102124
{:events [:chat.ui/camera-roll-select-album]}
103125
[{:keys [db]} album]

src/status_im2/contexts/chat/photo_selector/view.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
[album-selector/album-selector sheet album? selected-album top])
126126
[:<>
127127
[gesture/flat-list
128-
{:key-fn identity
128+
{:key-fn #(hash (:uri %))
129129
:render-fn render-image
130130
:render-data {:window-width window-width :selected selected-images}
131131
:data camera-roll-photos

src/status_im2/subs/chats.cljs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,18 @@
454454
[(re-frame/subscribe [:chats/chat (str community-id channel-id)])])
455455
(fn [[chat]]
456456
(:muted? chat)))
457+
458+
(re-frame/reg-sub
459+
:camera-roll/total-photos-count-android
460+
(fn [{:keys [camera-roll/albums]}]
461+
(->> albums
462+
:my-albums
463+
(reduce
464+
(fn [total-album-count current-album]
465+
(+ total-album-count (:count current-album)))
466+
0))))
467+
468+
(re-frame/reg-sub
469+
:camera-roll/total-photos-count-ios
470+
(fn [{:keys [camera-roll/ios-images-count]}]
471+
ios-images-count))

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,10 @@
21882188
dependencies:
21892189
merge-options "^3.0.4"
21902190

2191+
"@react-native-camera-roll/camera-roll@git+https://github.com/status-im/react-native-camera-roll.git#refs/tags/v5.1.1.1":
2192+
version "5.10.0"
2193+
resolved "git+https://github.com/status-im/react-native-camera-roll.git#174f8c6ad88e5bad9d9bd207f42173e567ec3138"
2194+
21912195
"@react-native-community/audio-toolkit@git+https://github.com/tbenr/react-native-audio-toolkit.git#refs/tags/v2.0.3-status-v6":
21922196
version "2.0.3"
21932197
resolved "git+https://github.com/tbenr/react-native-audio-toolkit.git#7ae9055cf6169b30f5089bda7bfcfc1c40a715e5"
@@ -2200,10 +2204,6 @@
22002204
version "4.3.3"
22012205
resolved "git+https://github.com/status-im/react-native-blur#c140cc8e7d54e3318af0a7c149b5d64b54de3419"
22022206

2203-
"@react-native-community/cameraroll@git+https://github.com/status-im/react-native-cameraroll.git#refs/tags/v4.0.4-status.0":
2204-
version "4.0.4"
2205-
resolved "git+https://github.com/status-im/react-native-cameraroll.git#337c5a515e9b0f0728882f73568075553415f523"
2206-
22072207
"@react-native-community/cli-clean@^8.0.4":
22082208
version "8.0.4"
22092209
resolved "https://registry.yarnpkg.com/@react-native-community/cli-clean/-/cli-clean-8.0.4.tgz#97e16a20e207b95de12e29b03816e8f2b2c80cc7"

0 commit comments

Comments
 (0)