Skip to content

Commit

Permalink
Merge pull request #568 from toya108/make-reverseContentLayout-extern…
Browse files Browse the repository at this point in the history
…ally-modifiable

make `reverseContentLayout` externally modifiable
  • Loading branch information
TimOliver authored Apr 6, 2024
2 parents d2aa60f + e0969c3 commit 63c8f6c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 6 deletions.
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

0 comments on commit 63c8f6c

Please sign in to comment.