mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 16:22:39 +00:00
The image preview is now displayed in fullscreen
This commit is contained in:
parent
f946d38dab
commit
37c3860cb5
4 changed files with 100 additions and 55 deletions
|
@ -55,5 +55,9 @@
|
|||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -30,7 +30,9 @@ typedef void (^blockCustomImageView_onClick)(CustomImageView *imageView, NSStrin
|
|||
@property (strong, nonatomic) NSDictionary *mediaInfo;
|
||||
|
||||
@property (strong, nonatomic) UIImage *image;
|
||||
@property (nonatomic) BOOL canBeZoomed;
|
||||
|
||||
@property (nonatomic) BOOL stretchable;
|
||||
@property (nonatomic) BOOL fullScreen;
|
||||
|
||||
// Let the user defines some custom buttons over the tabbar
|
||||
- (void)setLeftButtonTitle :leftButtonTitle handler:(blockCustomImageView_onClick)handler;
|
||||
|
|
|
@ -41,11 +41,13 @@
|
|||
//
|
||||
NSString* loadedImageURL;
|
||||
UIImage* _image;
|
||||
|
||||
BOOL useFullScreen;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation CustomImageView
|
||||
@synthesize canBeZoomed;
|
||||
@synthesize stretchable;
|
||||
|
||||
#define CUSTOM_IMAGE_VIEW_BUTTON_WIDTH 100
|
||||
|
||||
|
@ -68,6 +70,8 @@
|
|||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self stopActivityIndicator];
|
||||
|
||||
if (imageLoader) {
|
||||
[MediaManager cancel:imageLoader];
|
||||
imageLoader = nil;
|
||||
|
@ -118,14 +122,13 @@
|
|||
}
|
||||
|
||||
- (void)stopActivityIndicator {
|
||||
if (loadingWheel) {
|
||||
if (loadingWheel && loadingWheel.isAnimating) {
|
||||
[loadingWheel stopAnimating];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark - setters/getters
|
||||
|
||||
// image setter/getter
|
||||
- (void)setImage:(UIImage *)anImage {
|
||||
_image = anImage;
|
||||
|
||||
|
@ -137,6 +140,25 @@
|
|||
return _image;
|
||||
}
|
||||
|
||||
- (void)setFullScreen:(BOOL)fullScreen {
|
||||
useFullScreen = fullScreen;
|
||||
|
||||
[self initLayout];
|
||||
|
||||
if (useFullScreen) {
|
||||
[self removeFromSuperview];
|
||||
[UIApplication sharedApplication].statusBarHidden = YES;
|
||||
|
||||
self.frame = [AppDelegate theDelegate].window.rootViewController.view.bounds;
|
||||
[[AppDelegate theDelegate].window.rootViewController.view addSubview:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)fullScreen {
|
||||
return useFullScreen;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
- (IBAction)onButtonToggle:(id)sender
|
||||
{
|
||||
if (sender == leftButton) {
|
||||
|
@ -156,10 +178,17 @@
|
|||
UIButton* button = [[UIButton alloc] init];
|
||||
[button setTitle:title forState:UIControlStateNormal];
|
||||
[button setTitle:title forState:UIControlStateHighlighted];
|
||||
|
||||
// use the same text color as the tabbar
|
||||
[button setTitleColor:[AppDelegate theDelegate].masterTabBarController.tabBar.tintColor forState:UIControlStateNormal];
|
||||
[button setTitleColor:[AppDelegate theDelegate].masterTabBarController.tabBar.tintColor forState:UIControlStateHighlighted];
|
||||
|
||||
if (useFullScreen) {
|
||||
// use the same text color as the tabbar
|
||||
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
|
||||
}
|
||||
else {
|
||||
// use the same text color as the tabbar
|
||||
[button setTitleColor:[AppDelegate theDelegate].masterTabBarController.tabBar.tintColor forState:UIControlStateNormal];
|
||||
[button setTitleColor:[AppDelegate theDelegate].masterTabBarController.tabBar.tintColor forState:UIControlStateHighlighted];
|
||||
}
|
||||
|
||||
// keep the bottomView background color
|
||||
button.backgroundColor = [UIColor clearColor];
|
||||
|
@ -172,7 +201,7 @@
|
|||
|
||||
- (void)initScrollZoomFactors {
|
||||
// check if the image can be zoomed
|
||||
if (self.image && self.canBeZoomed && imageView.frame.size.width && imageView.frame.size.height) {
|
||||
if (self.image && self.stretchable && imageView.frame.size.width && imageView.frame.size.height) {
|
||||
// ensure that the content size is properly initialized
|
||||
scrollView.contentSize = scrollView.frame.size;
|
||||
|
||||
|
@ -202,11 +231,17 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
- (void)removeFromSuperview {
|
||||
[super removeFromSuperview];
|
||||
|
||||
// call upper layer
|
||||
[super layoutSubviews];
|
||||
if (useFullScreen) {
|
||||
[UIApplication sharedApplication].statusBarHidden = NO;
|
||||
}
|
||||
|
||||
[self stopActivityIndicator];
|
||||
}
|
||||
|
||||
- (void)initLayout {
|
||||
// create the subviews if they don't exist
|
||||
if (!scrollView) {
|
||||
scrollView = [[UIScrollView alloc] init];
|
||||
|
@ -219,20 +254,35 @@
|
|||
imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
[scrollView addSubview:imageView];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
|
||||
// call upper layer
|
||||
[super layoutSubviews];
|
||||
|
||||
[self initLayout];
|
||||
|
||||
// the image has been updated
|
||||
if (imageView.image != self.image) {
|
||||
imageView.image = self.image;
|
||||
}
|
||||
|
||||
CGRect tabBarFrame = [AppDelegate theDelegate].masterTabBarController.tabBar.frame;
|
||||
|
||||
// update the scrollview frame
|
||||
CGRect oneSelfFrame = CGRectIntegral(self.frame);
|
||||
CGRect oneSelfFrame = self.frame;
|
||||
CGRect scrollViewFrame = CGRectIntegral(scrollView.frame);
|
||||
|
||||
if (leftButtonTitle || rightButtonTitle) {
|
||||
oneSelfFrame.size.height -= tabBarFrame.size.height;
|
||||
}
|
||||
|
||||
oneSelfFrame = CGRectIntegral(oneSelfFrame);
|
||||
oneSelfFrame.origin = scrollViewFrame.origin = CGPointZero;
|
||||
|
||||
// use integral rect to avoid rounded value issue (float precision)
|
||||
if (!CGRectEqualToRect(CGRectIntegral(self.frame), CGRectIntegral(scrollView.frame))) {
|
||||
if (!CGRectEqualToRect(oneSelfFrame, scrollViewFrame)) {
|
||||
scrollView.frame = oneSelfFrame;
|
||||
imageView.frame = oneSelfFrame;
|
||||
|
||||
|
@ -255,16 +305,27 @@
|
|||
rightButton = [self addbuttonWithTitle:rightButtonTitle];
|
||||
}
|
||||
|
||||
// default tabbar background color
|
||||
CGFloat base = 248.0 / 255.0f;
|
||||
bottomBarView.backgroundColor = [UIColor colorWithRed:base green:base blue:base alpha:1.0];
|
||||
|
||||
[[AppDelegate theDelegate].masterTabBarController.tabBar addSubview:bottomBarView];
|
||||
// in fullscreen, display both buttons above the view
|
||||
if (useFullScreen) {
|
||||
bottomBarView.backgroundColor = [UIColor blackColor];
|
||||
[self addSubview:bottomBarView];
|
||||
}
|
||||
// display them above the tabbar
|
||||
else {
|
||||
// default tabbar background color
|
||||
CGFloat base = 248.0 / 255.0f;
|
||||
|
||||
bottomBarView.backgroundColor = [UIColor colorWithRed:base green:base blue:base alpha:1.0];
|
||||
[[AppDelegate theDelegate].masterTabBarController.tabBar addSubview:bottomBarView];
|
||||
}
|
||||
}
|
||||
|
||||
if (useFullScreen) {
|
||||
tabBarFrame.origin.y = self.frame.size.height - tabBarFrame.size.height;
|
||||
}
|
||||
else {
|
||||
tabBarFrame.origin.y = 0;
|
||||
}
|
||||
|
||||
// manage the item
|
||||
CGRect tabBarFrame = [AppDelegate theDelegate].masterTabBarController.tabBar.frame;
|
||||
tabBarFrame.origin.y = 0;
|
||||
bottomBarView.frame = tabBarFrame;
|
||||
|
||||
if (leftButton) {
|
||||
|
@ -354,13 +415,17 @@
|
|||
[bottomBarView removeFromSuperview];
|
||||
bottomBarView = nil;
|
||||
}
|
||||
|
||||
if (useFullScreen) {
|
||||
[UIApplication sharedApplication].statusBarHidden = NO;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UIScrollViewDelegate
|
||||
// require to be able to zoom an image
|
||||
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
|
||||
{
|
||||
return self.canBeZoomed ? imageView : nil;
|
||||
return self.stretchable ? imageView : nil;
|
||||
}
|
||||
|
||||
@end
|
|
@ -85,9 +85,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
// Local echo
|
||||
NSMutableArray *pendingOutgoingEvents;
|
||||
NSMutableArray *tmpCachedAttachments;
|
||||
|
||||
// the left bar button is replaced by a custom one when the image is zoomed
|
||||
UIBarButtonItem* defaultLeftBarButtonItem;
|
||||
}
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UINavigationItem *roomNavItem;
|
||||
|
@ -840,9 +837,9 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
NSString *url = content[@"url"];
|
||||
if (url.length) {
|
||||
highResImageView = [[CustomImageView alloc] initWithFrame:self.membersView.frame];
|
||||
highResImageView.canBeZoomed = YES;
|
||||
highResImageView.stretchable = YES;
|
||||
highResImageView.fullScreen = YES;
|
||||
[highResImageView setImageURL:url withPreviewImage:attachment.image];
|
||||
[self.view addSubview:highResImageView];
|
||||
|
||||
// Add tap recognizer to hide attachment
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideAttachmentView)];
|
||||
|
@ -850,15 +847,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
[tap setNumberOfTapsRequired:1];
|
||||
[highResImageView addGestureRecognizer:tap];
|
||||
highResImageView.userInteractionEnabled = YES;
|
||||
|
||||
defaultLeftBarButtonItem = self.navigationItem.leftBarButtonItem;
|
||||
|
||||
// add a button to close the ImageView
|
||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
|
||||
initWithTitle:@"Close"
|
||||
style:UIBarButtonItemStylePlain
|
||||
target:self
|
||||
action:@selector(dismissCustomImageView)];
|
||||
}
|
||||
} else if (msgtype == RoomMessageTypeVideo) {
|
||||
NSString *url =content[@"url"];
|
||||
|
@ -2209,13 +2197,11 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
[self.imageValidationView dismissSelection];
|
||||
[self.imageValidationView removeFromSuperview];
|
||||
self.imageValidationView = nil;
|
||||
self.navigationItem.leftBarButtonItem = defaultLeftBarButtonItem;
|
||||
}
|
||||
|
||||
if (highResImageView) {
|
||||
[highResImageView removeFromSuperview];
|
||||
highResImageView = nil;
|
||||
self.navigationItem.leftBarButtonItem = defaultLeftBarButtonItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2238,7 +2224,8 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
// else it would include a status bar height offset
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.imageValidationView = [[CustomImageView alloc] initWithFrame:self.membersView.frame];
|
||||
self.imageValidationView.canBeZoomed = YES;
|
||||
self.imageValidationView.stretchable = YES;
|
||||
self.imageValidationView.fullScreen = YES;
|
||||
|
||||
// the user validates the image
|
||||
[self.imageValidationView setRightButtonTitle:@"OK" handler:^(CustomImageView* imageView, NSString* buttonTitle) {
|
||||
|
@ -2265,19 +2252,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
}];
|
||||
|
||||
self.imageValidationView.image = selectedImage;
|
||||
|
||||
defaultLeftBarButtonItem = self.navigationItem.leftBarButtonItem;
|
||||
|
||||
// add a button to close the ImageView
|
||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
|
||||
initWithTitle:@"Close"
|
||||
style:UIBarButtonItemStylePlain
|
||||
target:self
|
||||
action:@selector(dismissCustomImageView)];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.view addSubview:self.imageValidationView];
|
||||
});
|
||||
});
|
||||
} else {
|
||||
[weakSelf sendImage:selectedImage];
|
||||
|
|
Loading…
Reference in a new issue