Skip to content

可以动态去适配RTL布局(阿拉伯语) #119

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
6 changes: 6 additions & 0 deletions TYCyclePagerViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
00EF9DC72C9195A80048F754 /* TYRTLCyclePagerTransformLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 00EF9DC62C9195A80048F754 /* TYRTLCyclePagerTransformLayout.m */; };
2B9C0EF61F0B2F32009BC0BD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B9C0EF51F0B2F32009BC0BD /* main.m */; };
2B9C0EF91F0B2F32009BC0BD /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B9C0EF81F0B2F32009BC0BD /* AppDelegate.m */; };
2B9C0EFC1F0B2F32009BC0BD /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B9C0EFB1F0B2F32009BC0BD /* ViewController.m */; };
Expand All @@ -31,6 +32,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
00EF9DC52C9195A80048F754 /* TYRTLCyclePagerTransformLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TYRTLCyclePagerTransformLayout.h; sourceTree = "<group>"; };
00EF9DC62C9195A80048F754 /* TYRTLCyclePagerTransformLayout.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TYRTLCyclePagerTransformLayout.m; sourceTree = "<group>"; };
2B9C0EF11F0B2F32009BC0BD /* TYCyclePagerViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TYCyclePagerViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
2B9C0EF51F0B2F32009BC0BD /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
2B9C0EF71F0B2F32009BC0BD /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -133,6 +136,8 @@
2B9C0F1D1F0B2F62009BC0BD /* TYCyclePagerView.m */,
2B9C0F1A1F0B2F62009BC0BD /* TYCyclePagerTransformLayout.h */,
2B9C0F1B1F0B2F62009BC0BD /* TYCyclePagerTransformLayout.m */,
00EF9DC52C9195A80048F754 /* TYRTLCyclePagerTransformLayout.h */,
00EF9DC62C9195A80048F754 /* TYRTLCyclePagerTransformLayout.m */,
2B9C0F1E1F0B2F62009BC0BD /* TYPageControl.h */,
2B9C0F1F1F0B2F62009BC0BD /* TYPageControl.m */,
);
Expand Down Expand Up @@ -249,6 +254,7 @@
2B9C0EF91F0B2F32009BC0BD /* AppDelegate.m in Sources */,
2B9C0F251F0B2F96009BC0BD /* TYCyclePagerViewCell.m in Sources */,
2B9C0F201F0B2F62009BC0BD /* TYCyclePagerTransformLayout.m in Sources */,
00EF9DC72C9195A80048F754 /* TYRTLCyclePagerTransformLayout.m in Sources */,
2B9C0EF61F0B2F32009BC0BD /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
6 changes: 6 additions & 0 deletions TYCyclePagerViewDemo/TYCyclePagerView/TYCyclePagerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ typedef NS_ENUM(NSUInteger, TYPagerScrollDirection) {

@interface TYCyclePagerView : UIView

/// initialize and determine RTL Adaptation
- (instancetype)initWithFrame:(CGRect)frame isAutoRTL:(BOOL)isAutoRTL;

/// is use RTL Adaptation
@property (nonatomic, assign) BOOL isAutoRTL;

// will be automatically resized to track the size of the pagerView
@property (nonatomic, strong, nullable) UIView *backgroundView;

Expand Down
38 changes: 37 additions & 1 deletion TYCyclePagerViewDemo/TYCyclePagerView/TYCyclePagerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "TYCyclePagerView.h"
#import "TYRTLCyclePagerTransformLayout.h"

NS_INLINE BOOL TYEqualIndexSection(TYIndexSection indexSection1,TYIndexSection indexSection2) {
return indexSection1.index == indexSection2.index && indexSection1.section == indexSection2.section;
Expand Down Expand Up @@ -58,6 +59,15 @@ @implementation TYCyclePagerView

#pragma mark - life Cycle

- (instancetype)initWithFrame:(CGRect)frame isAutoRTL:(BOOL)isAutoRTL {
if (self = [super initWithFrame:frame]) {
[self configureProperty];
_isAutoRTL = isAutoRTL;
[self addCollectionView];
}
return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self configureProperty];
Expand All @@ -77,6 +87,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder {
}

- (void)configureProperty {
_isAutoRTL = NO;
_needResetIndex = NO;
_didReloadData = NO;
_didLayout = NO;
Expand All @@ -90,7 +101,12 @@ - (void)configureProperty {
}

- (void)addCollectionView {
TYCyclePagerTransformLayout *layout = [[TYCyclePagerTransformLayout alloc]init];
TYCyclePagerTransformLayout *layout;
if (self.isAutoRTL) {
layout = [[TYRTLCyclePagerTransformLayout alloc] init];
} else {
layout = [[TYCyclePagerTransformLayout alloc] init];
}
UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
layout.delegate = _delegateFlags.applyTransformToAttributes ? self : nil;;
collectionView.backgroundColor = [UIColor clearColor];
Expand Down Expand Up @@ -202,6 +218,26 @@ - (NSArray *)visibleIndexs {

#pragma mark - setter

- (void)setIsAutoRTL:(BOOL)isAutoRTL {
if (_isAutoRTL == isAutoRTL) return;
_isAutoRTL = isAutoRTL;

TYCyclePagerTransformLayout *newLayout;
if (isAutoRTL) {
newLayout = [[TYRTLCyclePagerTransformLayout alloc] init];
} else {
newLayout = [[TYCyclePagerTransformLayout alloc] init];
}

TYCyclePagerTransformLayout *oldLayout = (TYCyclePagerTransformLayout *)self.collectionView.collectionViewLayout;
oldLayout.delegate = nil;

newLayout.layout = oldLayout.layout;

self.collectionView.collectionViewLayout = newLayout;
newLayout.delegate = _delegateFlags.applyTransformToAttributes ? self : nil;
}

- (void)setBackgroundView:(UIView *)backgroundView {
[_collectionView setBackgroundView:backgroundView];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// TYRTLCyclePagerTransformLayout.h
// TYCyclePagerViewDemo
//
// Created by aa on 2024/9/11.
// Copyright © 2024 tany. All rights reserved.
//

#import "TYCyclePagerTransformLayout.h"

NS_ASSUME_NONNULL_BEGIN

@interface TYRTLCyclePagerTransformLayout : TYCyclePagerTransformLayout

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// TYRTLCyclePagerTransformLayout.m
// TYCyclePagerViewDemo
//
// Created by aa on 2024/9/11.
// Copyright © 2024 tany. All rights reserved.
//

#import "TYRTLCyclePagerTransformLayout.h"

@implementation TYRTLCyclePagerTransformLayout

- (BOOL)flipsHorizontallyInOppositeLayoutDirection {
UIWindow *window = [UIApplication sharedApplication].delegate.window;
if (!window) {
return UIUserInterfaceLayoutDirectionLeftToRight;
}

UIUserInterfaceLayoutDirection layoutDirection = [UIView userInterfaceLayoutDirectionForSemanticContentAttribute:window.semanticContentAttribute];
return layoutDirection == UIUserInterfaceLayoutDirectionRightToLeft;
}

@end