Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make reverseContentLayout externally modifiable #568

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Objective-C/TOCropViewController/TOCropViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@
*/
@property (nonatomic, assign) BOOL cancelButtonHidden;

/**
When enabled, the toolbar is displayed in RTL layout.

Default is NO.
*/
@property (nonatomic, assign) BOOL reverseContentLayout
;

/**
If `showActivitySheetOnDone` is true, then these activity items will
be supplied to that UIActivityViewController in addition to the
Expand Down
10 changes: 10 additions & 0 deletions Objective-C/TOCropViewController/TOCropViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,16 @@ - (BOOL)cancelButtonHidden
return self.toolbar.cancelButtonHidden;
}

- (BOOL)reverseContentLayout
{
return self.toolbar.reverseContentLayout;
}
- (void)setReverseContentLayout:(BOOL)reverseContentLayout
{

self.toolbar.reverseContentLayout = reverseContentLayout;
}

- (void)setResetAspectRatioEnabled:(BOOL)resetAspectRatioEnabled
{
self.cropView.resetAspectRatioEnabled = resetAspectRatioEnabled;
Expand Down
3 changes: 3 additions & 0 deletions Objective-C/TOCropViewController/Views/TOCropToolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) BOOL doneButtonHidden;
@property (nonatomic, assign) BOOL cancelButtonHidden;

/* For languages like Arabic where they natively present content flipped from English */
@property (nonatomic, assign) BOOL reverseContentLayout;

/* Enable the reset button */
@property (nonatomic, assign) BOOL resetButtonEnabled;

Expand Down
14 changes: 10 additions & 4 deletions Objective-C/TOCropViewController/Views/TOCropToolbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ @interface TOCropToolbar()

@property (nonatomic, strong) UIButton *rotateButton; // defaults to counterclockwise button for legacy compatibility

@property (nonatomic, assign) BOOL reverseContentLayout; // For languages like Arabic where they natively present content flipped from English

@end

@implementation TOCropToolbar
Expand All @@ -61,10 +59,10 @@ - (void)setup {

// On iOS 9, we can use the new layout features to determine whether we're in an 'Arabic' style language mode
if (@available(iOS 9.0, *)) {
self.reverseContentLayout = ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:self.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft);
_reverseContentLayout = ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:self.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft);
}
else {
self.reverseContentLayout = [[[NSLocale preferredLanguages] objectAtIndex:0] hasPrefix:@"ar"];
_reverseContentLayout = [[[NSLocale preferredLanguages] objectAtIndex:0] hasPrefix:@"ar"];
}

// Get the resource bundle depending on the framework/dependency manager we're using
Expand Down Expand Up @@ -343,6 +341,14 @@ - (CGRect)clampButtonFrame
return self.clampButton.frame;
}

- (void)setReverseContentLayout:(BOOL)reverseContentLayout {
if (_reverseContentLayout == reverseContentLayout)
return;

_reverseContentLayout = reverseContentLayout;
[self setNeedsLayout];
}

- (void)setClampButtonHidden:(BOOL)clampButtonHidden {
if (_clampButtonHidden == clampButtonHidden)
return;
Expand Down
4 changes: 3 additions & 1 deletion Objective-C/TOCropViewControllerExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking

//cropController.rotateButtonsHidden = YES;
//cropController.rotateClockwiseButtonHidden = NO;


//cropController.reverseContentLayout = YES;

//cropController.doneButtonTitle = @"Title";
//cropController.cancelButtonTitle = @"Title";

Expand Down
13 changes: 12 additions & 1 deletion Swift/CropViewController/CropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,18 @@ open class CropViewController: UIViewController, TOCropViewControllerDelegate {
set { toCropViewController.cancelButtonColor = newValue }
get { return toCropViewController.cancelButtonColor }
}


/**
A computed property to get or set the reverse layout on toolbar.
By setting this property, you can control the direction in which the toolbar is laid out.

Default is NO.
*/
public var reverseContentLayout: Bool {
set { toCropViewController.reverseContentLayout = newValue }
get { toCropViewController.reverseContentLayout }
}

/**
This class internally manages and abstracts access to a `TOCropViewController` instance
:nodoc:
Expand Down
3 changes: 3 additions & 0 deletions Swift/CropViewControllerExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class ViewController: UIViewController, CropViewControllerDelegate, UIImagePicke
// cropController.doneButtonColor = UIColor.red
// cropController.cancelButtonColor = UIColor.green

// Change toolbar layout direction
// cropController.toolbar.reverseContentLayout = true

self.image = image

//If profile picture, push onto the same navigation stack
Expand Down