Skip to content

Commit

Permalink
WIP replace image viewer for ios17 support
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichAltheide committed Oct 9, 2023
1 parent 0982b51 commit dadcb82
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 145 deletions.
33 changes: 33 additions & 0 deletions Monal/Classes/ImageViewer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// ImageViewer.swift
// Monal
//
// Created by Friedrich Altheide on 07.10.23.
// Copyright © 2023 monal-im.org. All rights reserved.
//

import SwiftUI

struct ImageViewer: View {
var delegate: SheetDismisserProtocol
let image: UIImage

@State private var imageScale: CGFloat = 1.0

var body: some View {
Image(uiImage: image)
.resizable()
.scaledToFit()
.scaleEffect(imageScale)
.gesture(
MagnificationGesture()
.onChanged { value in
self.imageScale = value.magnitude
}
)
}
}

// #Preview {
// ImageViewer()
// }
9 changes: 9 additions & 0 deletions Monal/Classes/SwiftuiHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ class SwiftuiInterface : NSObject {
return host
}

@objc
func makeImageViewer(_ image: UIImage) -> UIViewController {
let delegate = SheetDismisserProtocol()
let host = UIHostingController(rootView:AnyView(EmptyView()))
delegate.host = host
host.rootView = AnyView(AddTopLevelNavigation(withDelegate:delegate, to:ImageViewer(delegate:delegate, image: image)))
return host
}

@objc
func makeOwnOmemoKeyView(_ ownContact: MLContact?) -> UIViewController {
let delegate = SheetDismisserProtocol()
Expand Down
53 changes: 6 additions & 47 deletions Monal/Classes/chatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

#import <Monal-Swift.h>
#import <stdatomic.h>
#import "IDMPhotoBrowser.h"

#define UPLOAD_TYPE_IMAGE @"UploadTypeImage";
#define UPLOAD_TYPE_URL @"UploadTypeURL";
Expand All @@ -48,7 +47,7 @@

@class MLEmoji;

@interface chatViewController()<IDMPhotoBrowserDelegate, ChatInputActionDelegage, UISearchControllerDelegate>
@interface chatViewController()<ChatInputActionDelegage, UISearchControllerDelegate>
{
BOOL _isTyping;
monal_void_block_t _cancelTypingNotification;
Expand All @@ -67,7 +66,6 @@ @interface chatViewController()<IDMPhotoBrowserDelegate, ChatInputActionDelegage
@property (nonatomic, strong) UIBarButtonItem* callButton;

@property (nonatomic, strong) NSMutableArray<MLMessage*>* messageList;
@property (nonatomic, strong) NSMutableArray* photos;
@property (nonatomic, strong) UIDocumentPickerViewController* filePicker;

@property (nonatomic, assign) BOOL sendLocation; // used for first request
Expand Down Expand Up @@ -2333,34 +2331,12 @@ -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
//TODO: fork swiftui image viewer (https://github.com/Jake-Short/swiftui-image-viewer),
//TODO: add support for FLAnimatedImage (https://github.com/Flipboard/FLAnimatedImage) using NSViewRepresentable
//TODO: or this so answer using quartz: https://stackoverflow.com/a/70369611/3528174
self.photos = [NSMutableArray new];
MLChatImageCell* imageCell = (MLChatImageCell *) cell;
IDMPhoto* photo = [IDMPhoto photoWithImage:[imageCell getDisplayedImage]];
// photo.caption=[row objectForKey:@"caption"];
[self.photos addObject:photo];
dispatch_async(dispatch_get_main_queue(), ^{
MLChatImageCell* imageCell = (MLChatImageCell *) cell;
UIViewController* photosViewer = [[SwiftuiInterface new] makeImageViewer:[imageCell getDisplayedImage]];
[self presentViewController:photosViewer animated:YES completion:^{}];
});
}

dispatch_async(dispatch_get_main_queue(), ^{
if(self.photos.count > 0) {
IDMPhotoBrowser* browser = [[IDMPhotoBrowser alloc] initWithPhotos:self.photos];
browser.delegate=self;

UIBarButtonItem* close = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", @"") style:UIBarButtonItemStyleDone target:self action:@selector(closePhotos)];
browser.navigationItem.leftBarButtonItem = close;

// browser.displayActionButton = YES; // Show action button to allow sharing, copying, etc (defaults to YES)
// browser.displayNavArrows = NO; // Whether to display left and right nav arrows on toolbar (defaults to NO)
// browser.displaySelectionButtons = NO; // Whether selection buttons are shown on each image (defaults to NO)
// browser.zoomPhotosToFill = YES; // Images that almost fill the screen will be initially zoomed to fill (defaults to YES)
// browser.alwaysShowControls = NO; // Allows to control whether the bars and controls are always visible or whether they fade away to show the photo full (defaults to NO)
// browser.enableGrid = YES; // Whether to allow the viewing of all the photo thumbnails on a grid (defaults to YES)
// browser.startOnGrid = NO; // Whether to start on the grid of thumbnails instead of the first photo (defaults to NO)
//
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:browser];

[self presentViewController:nav animated:YES completion:nil];
}
});
}
}
}
Expand Down Expand Up @@ -3051,23 +3027,6 @@ -(void) downloadPreviewWithRow:(NSIndexPath*) indexPath usingByterange:(BOOL) us
}] resume];
}

#pragma mark - photo browser delegate

-(NSUInteger)numberOfPhotosInPhotoBrowser:(IDMPhotoBrowser*) photoBrowser
{
return self.photos.count;
}

-(id<IDMPhoto>) photoBrowser:(IDMPhotoBrowser*) photoBrowser photoAtIndex:(NSUInteger) index
{
if (index < self.photos.count)
{
return [self.photos objectAtIndex:index];
}
return nil;
}


#pragma mark - Keyboard

- (void)keyboardWillDisappear:(NSNotification*) aNotification
Expand Down
4 changes: 4 additions & 0 deletions Monal/Monal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
C104918B261301530054AC9E /* monalxmpp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26CC579223A0867400ABB92A /* monalxmpp.framework */; };
C1049199261301710054AC9E /* MLCryptoTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1049198261301710054AC9E /* MLCryptoTest.swift */; };
C12436142434AB5D00B8F074 /* MLAttributedLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = C12436132434AB5D00B8F074 /* MLAttributedLabel.m */; };
C13252E42AD45FDB00E7C068 /* ImageViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C13252E32AD45FDB00E7C068 /* ImageViewer.swift */; };
C13A0BCE26E78B7B00987E29 /* ContactDetailsHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = C19C919A26E26AF000F8CC57 /* ContactDetailsHeader.swift */; };
C13EBB8E24DC685C008AADDA /* MLPrivacySettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C13EBB8D24DC685C008AADDA /* MLPrivacySettingsViewController.m */; };
C1414E9D24312F0100948788 /* MLChatMapsCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C1414E9C24312F0100948788 /* MLChatMapsCell.m */; };
Expand Down Expand Up @@ -605,6 +606,7 @@
C1049198261301710054AC9E /* MLCryptoTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MLCryptoTest.swift; sourceTree = "<group>"; };
C12436122434AB5D00B8F074 /* MLAttributedLabel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MLAttributedLabel.h; sourceTree = "<group>"; };
C12436132434AB5D00B8F074 /* MLAttributedLabel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MLAttributedLabel.m; sourceTree = "<group>"; };
C13252E32AD45FDB00E7C068 /* ImageViewer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageViewer.swift; sourceTree = "<group>"; };
C132EA9426C92DD900BB9A67 /* pa */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pa; path = external/pa.lproj/Main.strings; sourceTree = "<group>"; };
C132EA9626C92DD900BB9A67 /* pa */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pa; path = external/pa.lproj/Settings.strings; sourceTree = "<group>"; };
C132EA9926C92DDA00BB9A67 /* pa */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pa; path = external/pa.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1348,6 +1350,7 @@
841B6F16297AFB340074F9B7 /* Calls */ = {
isa = PBXGroup;
children = (
C13252E32AD45FDB00E7C068 /* ImageViewer.swift */,
841B6F1B297B3CFC0074F9B7 /* AVCallUI.swift */,
841B6F19297B18720074F9B7 /* AccountPicker.swift */,
);
Expand Down Expand Up @@ -2027,6 +2030,7 @@
26FE3BCB1C61A6C3003CC230 /* MLResizingTextView.m in Sources */,
54F0B81928231691003664BD /* WelcomeLogIn.swift in Sources */,
E8CF9CC726249640001A1952 /* MLSettingsAboutViewController.m in Sources */,
C13252E42AD45FDB00E7C068 /* ImageViewer.swift in Sources */,
C10490492612ED2F0054AC9E /* MLEmoji.swift in Sources */,
3D06A515281FFCC000DDAE90 /* NotificationSettings.swift in Sources */,
2636C43F177BD58C001CA71F /* XMPPEdit.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Monal/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def monal
use_frameworks!
inhibit_all_warnings!
pod 'MBProgressHUD', '~> 1.2.0'
pod 'IDMPhotoBrowser'
pod 'SDWebImage'
pod 'DZNEmptyDataSet'
pod 'TOCropViewController'
pod 'NotificationBannerSwift', '~> 3.2.0'
Expand Down
24 changes: 6 additions & 18 deletions Monal/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
PODS:
- ASN1Decoder (1.9.0)
- DACircularProgress (2.3.1)
- DZNEmptyDataSet (1.8.1)
- FLAnimatedImage (1.0.17)
- IDMPhotoBrowser (1.11.3):
- DACircularProgress
- pop
- SDWebImage (= 4.0.0)
- KSCrash (1.15.27):
- KSCrash/Installations (= 1.15.27)
- KSCrash/Installations (1.15.27):
Expand Down Expand Up @@ -75,11 +70,10 @@ PODS:
- NotificationBannerSwift (3.2.1):
- MarqueeLabel (~> 4.3.0)
- SnapKit (~> 5.6.0)
- pop (1.0.12)
- SAMKeychain (1.5.3)
- SDWebImage (4.0.0):
- SDWebImage/Core (= 4.0.0)
- SDWebImage/Core (4.0.0)
- SDWebImage (5.18.2):
- SDWebImage/Core (= 5.18.2)
- SDWebImage/Core (5.18.2)
- SignalProtocolC (2.3.3)
- SignalProtocolObjC (1.1.1):
- SignalProtocolC (~> 2.3.3)
Expand All @@ -94,11 +88,11 @@ DEPENDENCIES:
- ASN1Decoder
- DZNEmptyDataSet
- FLAnimatedImage (~> 1.0)
- IDMPhotoBrowser
- KSCrash (from `https://github.com/monal-im/KSCrash`, branch `master`)
- MBProgressHUD (~> 1.2.0)
- NotificationBannerSwift (~> 3.2.0)
- SAMKeychain
- SDWebImage
- SignalProtocolC (from `https://github.com/monal-im/libsignal-protocol-c`, branch `master`)
- SignalProtocolObjC (from `https://github.com/monal-im/SignalProtocol-ObjC.git`, branch `master`)
- sqlite3/perf-threadsafe
Expand All @@ -108,14 +102,11 @@ DEPENDENCIES:
SPEC REPOS:
trunk:
- ASN1Decoder
- DACircularProgress
- DZNEmptyDataSet
- FLAnimatedImage
- IDMPhotoBrowser
- MarqueeLabel
- MBProgressHUD
- NotificationBannerSwift
- pop
- SAMKeychain
- SDWebImage
- SnapKit
Expand Down Expand Up @@ -147,24 +138,21 @@ CHECKOUT OPTIONS:

SPEC CHECKSUMS:
ASN1Decoder: 4f4bbcaf1d1b8be56daa3280e82863a607f5bda9
DACircularProgress: 4dd437c0fc3da5161cb289e07ac449493d41db71
DZNEmptyDataSet: 9525833b9e68ac21c30253e1d3d7076cc828eaa7
FLAnimatedImage: bbf914596368867157cc71b38a8ec834b3eeb32b
IDMPhotoBrowser: b96159fe4adb991a844068eb17dab9c0b7d7e51a
KSCrash: 202a2dd3a1a3a1aa0783056a42d7db8ea8bf3a56
MarqueeLabel: 15e524a6762552bb279cb17438b8a94990269fb9
MBProgressHUD: 3ee5efcc380f6a79a7cc9b363dd669c5e1ae7406
NotificationBannerSwift: dce54ded532b26e30cd8e7f4d80e124a0f2ba7d1
pop: d582054913807fd11fd50bfe6a539d91c7e1a55a
SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c
SDWebImage: 76a6348bdc74eb5a55dd08a091ef298e56b55e41
SDWebImage: c0de394d7cf7f9838aed1fd6bb6037654a4572e4
SignalProtocolC: 8092866e45b663a6bc3e45a8d13bad2571dbf236
SignalProtocolObjC: 1beb46b1d35733e7ab96a919f88bac20ec771c73
SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25
sqlite3: e0a0623a33a20a47cb5921552aebc6e9e437dc91
TOCropViewController: edfd4f25713d56905ad1e0b9f5be3fbe0f59c863
WebRTC-lib: 8e6d3ec41aea480ef844bb5d537cbefb83e7c2c2

PODFILE CHECKSUM: bf3a219fe79a10968ef750b2aeba39a10793cda6
PODFILE CHECKSUM: 99af97fbdbc651c2f1c5558cb9ba7107ef30aa28

COCOAPODS: 1.13.0
Loading

0 comments on commit dadcb82

Please sign in to comment.