From 7c54fb571d2837d0c457e3e17c01818fc434f8a2 Mon Sep 17 00:00:00 2001 From: Goffredo Marocchi Date: Sun, 5 Mar 2017 14:59:36 +0000 Subject: [PATCH] Improved compatibility. * Improved compatibility with UIActivityIndicator by providing a protocol compatible with both. * Using a common protocol allows the user to make his implementation decoupled from this spinner or UIKit's default one. * Improved compatibility with MBProgressHUD by implementing intrinsicContentSize and content size invalidation. Signed-off-by: Goffredo Marocchi --- .../project.pbxproj | 6 +-- Example/Podfile | 4 +- MMMaterialDesignSpinner.podspec | 8 +-- .../project.pbxproj | 4 ++ Pod/Classes/ActivityTracking.h | 53 +++++++++++++++++++ Pod/Classes/MMMaterialDesignSpinner.h | 37 +------------ Pod/Classes/MMMaterialDesignSpinner.m | 13 +++++ Pod/Info.plist | 2 +- 8 files changed, 81 insertions(+), 46 deletions(-) create mode 100644 Pod/Classes/ActivityTracking.h diff --git a/Example/MaterialDesignSpinner.xcodeproj/project.pbxproj b/Example/MaterialDesignSpinner.xcodeproj/project.pbxproj index 8a69a8a..b3821f6 100644 --- a/Example/MaterialDesignSpinner.xcodeproj/project.pbxproj +++ b/Example/MaterialDesignSpinner.xcodeproj/project.pbxproj @@ -484,7 +484,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -516,7 +516,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -531,7 +531,6 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "MaterialDesignSpinner/MaterialDesignSpinner-Prefix.pch"; INFOPLIST_FILE = "MaterialDesignSpinner/MaterialDesignSpinner-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -545,7 +544,6 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "MaterialDesignSpinner/MaterialDesignSpinner-Prefix.pch"; INFOPLIST_FILE = "MaterialDesignSpinner/MaterialDesignSpinner-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; diff --git a/Example/Podfile b/Example/Podfile index 1f7ff4e..1abe40f 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -1,10 +1,10 @@ platform :ios, '8.0' use_frameworks! -target 'MaterialDesignSpinner', :exclusive => true do +target 'MaterialDesignSpinner' do pod "MMMaterialDesignSpinner", :path => "../" end -target 'Tests', :exclusive => true do +target 'Tests' do pod "MMMaterialDesignSpinner", :path => "../" end diff --git a/MMMaterialDesignSpinner.podspec b/MMMaterialDesignSpinner.podspec index e8077ea..7f74306 100644 --- a/MMMaterialDesignSpinner.podspec +++ b/MMMaterialDesignSpinner.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "MMMaterialDesignSpinner" - s.version = "0.2.3" + s.version = "0.2.6" s.summary = "An iOS activity spinner modeled after Google's Material Design spinner" # This description is used to generate tags and improve search results. @@ -34,7 +34,7 @@ Pod::Spec.new do |s| * [kylefox / color.m gist](https://gist.github.com/kylefox/1689973) for creating random UIColor values. DESC - s.homepage = "https://github.com/misterwell/MMMaterialDesignSpinner" + s.homepage = "https://github.com/misterwell/MMMaterialDesignSpinner.git" # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" @@ -72,7 +72,7 @@ Pod::Spec.new do |s| # s.platform = :ios, "5.0" # When using multiple platforms - s.ios.deployment_target = "5.0" + s.ios.deployment_target = "8.0" # s.osx.deployment_target = "10.7" # s.watchos.deployment_target = "2.0" s.tvos.deployment_target = "9.0" @@ -84,7 +84,7 @@ Pod::Spec.new do |s| # Supports git, hg, bzr, svn and HTTP. # - s.source = { :git => "https://github.com/misterwell/MMMaterialDesignSpinner.git", :tag => "0.2.3" } + s.source = { :git => "https://github.com/misterwell/MMMaterialDesignSpinner.git", :tag => "0.2.6" } # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # diff --git a/MMMaterialDesignSpinner.xcodeproj/project.pbxproj b/MMMaterialDesignSpinner.xcodeproj/project.pbxproj index 1588f4d..d5ee0a4 100644 --- a/MMMaterialDesignSpinner.xcodeproj/project.pbxproj +++ b/MMMaterialDesignSpinner.xcodeproj/project.pbxproj @@ -7,12 +7,14 @@ objects = { /* Begin PBXBuildFile section */ + 75A8F60A1E6C2F8E00C7FF55 /* ActivityTracking.h in Headers */ = {isa = PBXBuildFile; fileRef = 75A8F6091E6C2F8E00C7FF55 /* ActivityTracking.h */; }; 9295C9501B253D8900C388EB /* MMMaterialDesignSpinner.h in Headers */ = {isa = PBXBuildFile; fileRef = 9295C94E1B253D8900C388EB /* MMMaterialDesignSpinner.h */; settings = {ATTRIBUTES = (Public, ); }; }; 9295C9511B253D8900C388EB /* MMMaterialDesignSpinner.m in Sources */ = {isa = PBXBuildFile; fileRef = 9295C94F1B253D8900C388EB /* MMMaterialDesignSpinner.m */; }; 9295C9531B253D9F00C388EB /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9295C9521B253D9F00C388EB /* Info.plist */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 75A8F6091E6C2F8E00C7FF55 /* ActivityTracking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ActivityTracking.h; path = Pod/Classes/ActivityTracking.h; sourceTree = SOURCE_ROOT; }; 9295C9321B253D2D00C388EB /* MMMaterialDesignSpinner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MMMaterialDesignSpinner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9295C94E1B253D8900C388EB /* MMMaterialDesignSpinner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MMMaterialDesignSpinner.h; path = Pod/Classes/MMMaterialDesignSpinner.h; sourceTree = SOURCE_ROOT; }; 9295C94F1B253D8900C388EB /* MMMaterialDesignSpinner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MMMaterialDesignSpinner.m; path = Pod/Classes/MMMaterialDesignSpinner.m; sourceTree = SOURCE_ROOT; }; @@ -51,6 +53,7 @@ children = ( 9295C94E1B253D8900C388EB /* MMMaterialDesignSpinner.h */, 9295C94F1B253D8900C388EB /* MMMaterialDesignSpinner.m */, + 75A8F6091E6C2F8E00C7FF55 /* ActivityTracking.h */, 9295C9351B253D2D00C388EB /* Supporting Files */, ); path = MMMaterialDesignSpinner; @@ -71,6 +74,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 75A8F60A1E6C2F8E00C7FF55 /* ActivityTracking.h in Headers */, 9295C9501B253D8900C388EB /* MMMaterialDesignSpinner.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Pod/Classes/ActivityTracking.h b/Pod/Classes/ActivityTracking.h new file mode 100644 index 0000000..da608e6 --- /dev/null +++ b/Pod/Classes/ActivityTracking.h @@ -0,0 +1,53 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +#import + +@protocol ActivityTracking + +// default is UIActivityIndicatorViewStyleWhite +@property(nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; + +// default is YES. calls -setHidden when animating gets set to NO +@property(nonatomic) BOOL hidesWhenStopped; + +@property (nullable, readwrite, nonatomic, strong) UIColor *color NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; + +/** Sets the line width of the spinner's circle. */ +@property (nonatomic) CGFloat lineWidth; + +/** Specifies the timing function to use for the control's animation. Defaults to kCAMediaTimingFunctionEaseInEaseOut */ +@property (nullable, nonatomic, strong) CAMediaTimingFunction *timingFunction; + +/** Property indicating the duration of the animation, default is 1.5s. Should be set prior to -[startAnimating] */ +@property (nonatomic, readwrite) NSTimeInterval duration; + +/** + * Convenience function for starting & stopping animation with a boolean variable instead of explicit + * method calls. + * + * @param animate true to start animating, false to stop animating. + @note This method simply calls the startAnimating or stopAnimating methods based on the value of the animate parameter. + */ +- (void)setAnimating:(BOOL)animate; +- (void)startAnimating; +- (void)stopAnimating; +- (BOOL)isAnimating; + +@end diff --git a/Pod/Classes/MMMaterialDesignSpinner.h b/Pod/Classes/MMMaterialDesignSpinner.h index 6b92c16..7fb43d7 100644 --- a/Pod/Classes/MMMaterialDesignSpinner.h +++ b/Pod/Classes/MMMaterialDesignSpinner.h @@ -7,6 +7,7 @@ // #import +#import "ActivityTracking.h" //! Project version number for MMMaterialDesignSpinner. FOUNDATION_EXPORT double MMMaterialDesignSpinnerVersionNumber; @@ -19,40 +20,6 @@ FOUNDATION_EXPORT const unsigned char MMMaterialDesignSpinnerVersionString[]; /** * A control similar to iOS' UIActivityIndicatorView modeled after Google's Material Design Activity spinner. */ -@interface MMMaterialDesignSpinner : UIView - -/** Sets the line width of the spinner's circle. */ -@property (nonatomic) CGFloat lineWidth; - -/** Sets whether the view is hidden when not animating. */ -@property (nonatomic) BOOL hidesWhenStopped; - -/** Specifies the timing function to use for the control's animation. Defaults to kCAMediaTimingFunctionEaseInEaseOut */ -@property (nonatomic, strong) CAMediaTimingFunction *timingFunction; - -/** Property indicating whether the view is currently animating. */ -@property (nonatomic, readonly) BOOL isAnimating; - -/** Property indicating the duration of the animation, default is 1.5s. Should be set prior to -[startAnimating] */ -@property (nonatomic, readwrite) NSTimeInterval duration; - -/** - * Convenience function for starting & stopping animation with a boolean variable instead of explicit - * method calls. - * - * @param animate true to start animating, false to stop animating. - @note This method simply calls the startAnimating or stopAnimating methods based on the value of the animate parameter. - */ -- (void)setAnimating:(BOOL)animate; - -/** - * Starts animation of the spinner. - */ -- (void)startAnimating; - -/** - * Stops animation of the spinnner. - */ -- (void)stopAnimating; +@interface MMMaterialDesignSpinner : UIView @end diff --git a/Pod/Classes/MMMaterialDesignSpinner.m b/Pod/Classes/MMMaterialDesignSpinner.m index c783a6c..72c3b10 100644 --- a/Pod/Classes/MMMaterialDesignSpinner.m +++ b/Pod/Classes/MMMaterialDesignSpinner.m @@ -19,6 +19,11 @@ static NSString *kMMRingRotationAnimationKey = @"mmmaterialdesignspinner.rotatio @implementation MMMaterialDesignSpinner @synthesize progressLayer=_progressLayer; +@synthesize hidesWhenStopped=_hidesWhenStopped; +@synthesize activityIndicatorViewStyle=_activityIndicatorViewStyle; +@synthesize color=_color; +@synthesize timingFunction=_timingFunction; +@synthesize duration=_duration; - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { @@ -36,6 +41,7 @@ static NSString *kMMRingRotationAnimationKey = @"mmmaterialdesignspinner.rotatio - (void)awakeFromNib { + [super awakeFromNib]; [self initialize]; } @@ -47,6 +53,7 @@ static NSString *kMMRingRotationAnimationKey = @"mmmaterialdesignspinner.rotatio // See comment in resetAnimations on why this notification is used. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetAnimations) name:UIApplicationDidBecomeActiveNotification object:nil]; + [self invalidateIntrinsicContentSize]; } - (void)dealloc @@ -58,9 +65,15 @@ static NSString *kMMRingRotationAnimationKey = @"mmmaterialdesignspinner.rotatio [super layoutSubviews]; self.progressLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)); + [self invalidateIntrinsicContentSize]; [self updatePath]; } +- (CGSize)intrinsicContentSize +{ + return CGSizeMake(self.bounds.size.width, self.bounds.size.height); +} + - (void)tintColorDidChange { [super tintColorDidChange]; diff --git a/Pod/Info.plist b/Pod/Info.plist index 11686c4..d9ad5ed 100644 --- a/Pod/Info.plist +++ b/Pod/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.2.1 + 0.2.6 CFBundleSignature ???? CFBundleVersion