Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.
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,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D03882F31BF0C704000F6400"
BuildableName = "MXPagerView-Swift.app"
BlueprintName = "MXPagerView-Swift"
ReferencedContainer = "container:MXPagerView-Swift.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D03882F31BF0C704000F6400"
BuildableName = "MXPagerView-Swift.app"
BlueprintName = "MXPagerView-Swift"
ReferencedContainer = "container:MXPagerView-Swift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D03882F31BF0C704000F6400"
BuildableName = "MXPagerView-Swift.app"
BlueprintName = "MXPagerView-Swift"
ReferencedContainer = "container:MXPagerView-Swift.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D03882F31BF0C704000F6400"
BuildableName = "MXPagerView-Swift.app"
BlueprintName = "MXPagerView-Swift"
ReferencedContainer = "container:MXPagerView-Swift.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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>SchemeUserState</key>
<dict>
<key>MXPagerView-Swift.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>D03882F31BF0C704000F6400</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions MXPagerView/MXPagerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ typedef NS_ENUM(NSInteger, MXPagerViewTransitionStyle) {
*/
@property (nonatomic, readonly) CGFloat progress;

/**
Determine if pages should be lazily loaded
*/
@property(assign) BOOL shouldLazyLoad;


/**
Reloads everything from scratch. redisplays pages.
*/
Expand Down
27 changes: 23 additions & 4 deletions MXPagerView/MXPagerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ @interface MXPagerView () <UIScrollViewDelegate, UIGestureRecognizerDelegate>

@property (nonatomic, strong) NSMutableDictionary *registration;
@property (nonatomic, strong) NSMutableArray *reuseQueue;

@end

@implementation MXPagerView {

CGFloat _index;
NSInteger _count;

Expand Down Expand Up @@ -114,8 +116,16 @@ - (void)reloadData {

//Updates index and loads the current selected page
if ( (_count = [self.dataSource numberOfPagesInPagerView:self]) > 0) {
_index = MIN(_index, _count - 1);
[self loadPageAtIndex:_index];
if (self.shouldLazyLoad) {
if (_index >= _count)
_index = _count-1;

[self loadPageAtIndex:_index];
}
else {
[self loadAllPages];
}

[self setNeedsLayout];
}
}
Expand Down Expand Up @@ -237,7 +247,7 @@ - (void)didMovePageToIndex:(NSInteger)index {
[self.delegate pagerView:self didMoveToPage:page atIndex:index];
}

//The page did change, now unload hidden pages
//The page did change, now unload hidden pages
[self unLoadHiddenPages];
}

Expand Down Expand Up @@ -271,13 +281,22 @@ - (void)loadPageAtIndex:(NSInteger)index {
loadPage(index);

//In case of slide behavior, its loads the neighbors as well.
if (self.transitionStyle == MXPagerViewTransitionStyleScroll) {
if (self.transitionStyle == MXPagerViewTransitionStyleScroll && self.shouldLazyLoad) {
loadPage(index - 1);
loadPage(index + 1);
}
}

- (void) loadAllPages {
for (int i = 0; i < _count; i++) {
[self loadPageAtIndex:i];
}
}

- (void)unLoadHiddenPages {
if (!self.shouldLazyLoad) {
return;
}

NSMutableArray *toUnLoad = [NSMutableArray array];

Expand Down