Skip to content

Commit

Permalink
Build example project and rename the core files.
Browse files Browse the repository at this point in the history
  • Loading branch information
xingheng committed Dec 15, 2016
1 parent 014c61a commit a1b0873
Show file tree
Hide file tree
Showing 25 changed files with 1,620 additions and 34 deletions.
53 changes: 53 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md

fastlane/report.xml
fastlane/screenshots
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// BaseViewController.h
// DSBaseViewController.h
// youyue
//
// Created by WeiHan on 12/3/15.
Expand Down Expand Up @@ -28,9 +28,14 @@
return self; \
}

typedef NSString * DSBaseViewControllerOptionKeyType;

FOUNDATION_EXPORT DSBaseViewControllerOptionKeyType const DSBaseViewControllerOptionBackgroundColor;
FOUNDATION_EXPORT DSBaseViewControllerOptionKeyType const DSBaseViewControllerOptionBackBarButtonImage;

typedef void (^AppearAnimationBlock)(BOOL);

@class BaseViewController;
@class DSBaseViewController;


#pragma mark - BuildViewDelegate
Expand All @@ -44,7 +49,7 @@ typedef void (^AppearAnimationBlock)(BOOL);
* @param containerView view controller's root view (self.view)
* @param viewController current view controller
*/
- (void)buildSubview:(UIView *)containerView controller:(BaseViewController *)viewController;
- (void)buildSubview:(UIView *)containerView controller:(DSBaseViewController *)viewController;

@optional

Expand All @@ -54,14 +59,14 @@ typedef void (^AppearAnimationBlock)(BOOL);
* returns NO, or appeared with receiving memory warning state.
* DO NOT call this method directly.
*/
- (void)loadDataForController:(BaseViewController *)viewController;
- (void)loadDataForController:(DSBaseViewController *)viewController;

/**
* @brief This method is used to unload data for viewController, it will be
* called when view controller is invisible and received some memory warnings.
* DO NOT call this method directly.
*/
- (void)tearDown:(BaseViewController *)viewController;
- (void)tearDown:(DSBaseViewController *)viewController;

/**
* @brief This method will be called when not receiving memory warning state
Expand All @@ -71,14 +76,14 @@ typedef void (^AppearAnimationBlock)(BOOL);
* and loadDataForController to reload data for viewController, otherwise,
* nothing will be done.
*/
- (BOOL)shouldInvalidateDataForController:(BaseViewController *)viewController;
- (BOOL)shouldInvalidateDataForController:(DSBaseViewController *)viewController;

@end


#pragma mark - BaseViewController
#pragma mark - DSBaseViewController

@interface BaseViewController : UIViewController
@interface DSBaseViewController : UIViewController

@property (nonatomic, assign, readonly) BOOL visible;

Expand All @@ -91,16 +96,18 @@ typedef void (^AppearAnimationBlock)(BOOL);
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (UIViewController *)popCurrentViewController; // with animation

+ (UIColor *)backgroundColor;

+ (UIImage *)backBarButtonImage;
+ (void)setupWithOption:(NSDictionary<DSBaseViewControllerOptionKeyType, id> *)options;

@end


// Should use this as base type for children view controllers.
typedef BaseViewController<BuildViewDelegate> BASEVIEWCONTROLLER;
typedef DSBaseViewController<BuildViewDelegate> DSBASEVIEWCONTROLLER;


#ifdef DS_SHORTHAND
typedef DSBaseViewController BaseViewController;
typedef DSBASEVIEWCONTROLLER BASEVIEWCONTROLLER;

/**
Use for easy to copy
Expand All @@ -121,7 +128,35 @@ typedef BaseViewController<BuildViewDelegate> BASEVIEWCONTROLLER;
- (BOOL)shouldInvalidateDataForController:(BaseViewController *)viewController
{
return NO;
return NO;
}
**/

#else

/**
Use for easy to copy
#pragma mark - BuildViewDelegate
- (void)buildSubview:(UIView *)containerView controller:(DSBaseViewController *)viewController
{
}
- (void)loadDataForController:(DSBaseViewController *)viewController
{
}
- (void)tearDown:(DSBaseViewController *)viewController
{
}
- (BOOL)shouldInvalidateDataForController:(DSBaseViewController *)viewController
{
return NO;
}
**/

#endif
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
//
// BaseViewController.m
// DSBaseViewController.m
// youyue
//
// Created by WeiHan on 12/3/15.
// Copyright © 2015 DragonSource. All rights reserved.
//

#import "BaseViewController.h"
#import "DSBaseViewController.h"

DSBaseViewControllerOptionKeyType const DSBaseViewControllerOptionBackgroundColor = @"DSBaseViewControllerOptionBackgroundColor";
DSBaseViewControllerOptionKeyType const DSBaseViewControllerOptionBackBarButtonImage = @"DSBaseViewControllerOptionBackBarButtonImage";


static UIColor *DSBaseViewControllerBackgroundColor;
static UIImage *DSBaseViewControllerBackBarButtonImage;


UIImage * GetBackBarButtonImage(CGRect rect);


@interface BaseViewController ()
#pragma mark - DSBaseViewController

@interface DSBaseViewController ()

@property (nonatomic, assign) BOOL fReceivedMemoryWarning;

@end

@implementation BaseViewController
@implementation DSBaseViewController

- (void)viewDidLoad
{
Expand Down Expand Up @@ -141,14 +151,17 @@ - (UIViewController *)popCurrentViewController
return [self.navigationController popViewControllerAnimated:YES];
}

+ (UIColor *)backgroundColor
+ (void)setupWithOption:(NSDictionary<DSBaseViewControllerOptionKeyType, id> *)options
{
return nil;
}

+ (UIImage *)backBarButtonImage
{
return GetBackBarButtonImage(CGRectMake(0, 0, 40, 30));
for (DSBaseViewControllerOptionKeyType key in options) {
if ([key isEqualToString:DSBaseViewControllerOptionBackgroundColor]) {
DSBaseViewControllerBackgroundColor = options[key];
} else if ([key isEqualToString:DSBaseViewControllerOptionBackBarButtonImage]) {
DSBaseViewControllerBackBarButtonImage = options[key];
} else {
DDLogError(@"Unexpected option key for %@ configuration, key: %@", NSStringFromClass([self class]), key);
}
}
}

#pragma mark - Property
Expand All @@ -163,14 +176,13 @@ - (BOOL)visible

- (void)_setupAppearance
{
UIColor *color = [[self class] backgroundColor];

if (color) {
self.view.backgroundColor = color;
if (DSBaseViewControllerBackgroundColor) {
self.view.backgroundColor = DSBaseViewControllerBackgroundColor;
}

if (self.navigationController.viewControllers.count > 1) {
UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithImage:[[self class] backBarButtonImage] style:UIBarButtonItemStylePlain target:self action:@selector(popCurrentViewController)];
UIImage *backBarImage = DSBaseViewControllerBackBarButtonImage ? : GetBackBarButtonImage(CGRectMake(0, 0, 10, 18));
UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithImage:backBarImage style:UIBarButtonItemStylePlain target:self action:@selector(popCurrentViewController)];
self.navigationItem.leftBarButtonItem = backBarButton;
}
}
Expand Down Expand Up @@ -235,16 +247,15 @@ - (BOOL)_hasInvalidStatusData
UIGraphicsBeginImageContext(rect.size);

UIBezierPath *bezierPath = UIBezierPath.bezierPath;
[bezierPath moveToPoint:CGPointMake(30.5, 66.5)];
[bezierPath addLineToPoint:CGPointMake(2.5, 36.5)];
[bezierPath addLineToPoint:CGPointMake(30.5, 2.5)];
[bezierPath moveToPoint:CGPointMake(8.0, 16.0)];
[bezierPath addLineToPoint:CGPointMake(1.0, 9.0)];
[bezierPath addLineToPoint:CGPointMake(8.0, 1.0)];
bezierPath.lineCapStyle = kCGLineCapRound;
bezierPath.lineJoinStyle = kCGLineJoinRound;

[UIColor.redColor setStroke];
bezierPath.lineWidth = 4;
bezierPath.lineWidth = 2;
[bezierPath stroke];

CGContextAddPath(context, bezierPath.CGPath);
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsPopContext();
Expand Down
Loading

0 comments on commit a1b0873

Please sign in to comment.