GithubHelp home page GithubHelp logo

yahooarchive / yangmingshan Goto Github PK

View Code? Open in Web Editor NEW
641.0 21.0 95.0 14.63 MB

YangMingShan is a collection of iOS UI components that we created while building Yahoo apps.

License: Other

Ruby 0.83% Objective-C 88.97% Swift 10.21%

yangmingshan's Introduction

Build Status CocoaPods Carthage compatible

YangMingShan is a collection of iOS UI components that we created while building Yahoo apps. The reason we open source it is to share useful and common components with the community. Feel free to open the feature request ticket for new UI component you see on Yahoo apps or send pull-request to benefit open source community.

Installation

YangMingShan can be installed via CocoaPods. Simply add

pod 'YangMingShan'

to your Podfile.

YangMingShan also supports Carthage. Simply add

github "yahoo/YangMingShan"

to your Cartfile.

The Components

A

YMSPhotoPicker

YMSPhotoPicker is an UIComponent that let you select multiple photos from your albums. You can also take a photo inside YMSPhotoPicker and select it with other photos. It has the exposed theme YMSPhotoPickerTheme that you can customize several parts of YMSPhotoPicker.

Part of the code in this package was derived from Yahoo Messenger and Yahoo Taiwan Auctions.

Square Cash Style Bar

Square Cash Style Bar

Usage

Add NSPhotoLibraryUsageDescription and NSCameraUsageDescription to your App Info.plist to specify the reason for accessing photo library and camera. See Cocoa Keys for more details.

#####Objective-C

Import

@import YangMingShan;

Add delegate to your view controller

@interface YourViewController ()<YMSPhotoPickerViewControllerDelegate>

Present default photo picker. Note it is only available for single selection

[self yms_presentAlbumPhotoViewWithDelegate:self];

Or init picker with limited photo selection of 10

YMSPhotoPickerViewController *pickerViewController = [[YMSPhotoPickerViewController alloc] init];
pickerViewController.numberOfPhotoToSelect = 10;

With customized theme

UIColor *customColor = [UIColor colorWithRed:64.0/255.0 green:0.0 blue:144.0/255.0 alpha:1.0];
UIColor *customCameraColor = [UIColor colorWithRed:86.0/255.0 green:1.0/255.0 blue:236.0/255.0 alpha:1.0];

pickerViewController.theme.titleLabelTextColor = [UIColor whiteColor];
        pickerViewController.theme.navigationBarBackgroundColor = customColor;
pickerViewController.theme.tintColor = [UIColor whiteColor];
pickerViewController.theme.orderTintColor = customCameraColor;
pickerViewController.theme.cameraVeilColor = customCameraColor;
pickerViewController.theme.cameraIconColor = [UIColor whiteColor];
pickerViewController.theme.statusBarStyle = UIStatusBarStyleLightContent;

Present customized picker

[self yms_presentCustomAlbumPhotoView:pickerViewController delegate:self];

Implement photoPickerViewControllerDidReceivePhotoAlbumAccessDenied: and photoPickerViewControllerDidReceiveCameraAccessDenied: to observe photo album and camera access denied occur

- (void)photoPickerViewControllerDidReceivePhotoAlbumAccessDenied:(YMSPhotoPickerViewController *)picker
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Allow photo album access?", nil) message:NSLocalizedString(@"Need your permission to access photo albums", nil) preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Settings", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }];
    [alertController addAction:dismissAction];
    [alertController addAction:settingsAction];

    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)photoPickerViewControllerDidReceiveCameraAccessDenied:(YMSPhotoPickerViewController *)picker
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Allow camera access?", nil) message:NSLocalizedString(@"Need your permission to take a photo", nil) preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Settings", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }];
    [alertController addAction:dismissAction];
    [alertController addAction:settingsAction];

    // The access denied of camera is always happened on picker, present alert on it to follow the view hierarchy
    [picker presentViewController:alertController animated:YES completion:nil];
}

Implement photoPickerViewController:didFinishPickingImages: while you expect there are multiple photo selections

- (void)photoPickerViewController:(YMSPhotoPickerViewController *)picker didFinishPickingImages:(NSArray *)photoAssets
{
    [picker dismissViewControllerAnimated:YES completion:^() {
        // Remember images you get here is PHAsset array, you need to implement PHImageManager to get UIImage data by yourself
        PHImageManager *imageManager = [[PHImageManager alloc] init];

        PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
        options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
        options.networkAccessAllowed = YES;
        options.resizeMode = PHImageRequestOptionsResizeModeExact;
        options.synchronous = YES;

        NSMutableArray *mutableImages = [NSMutableArray array];

        for (PHAsset *asset in photoAssets) {
            CGSize targetSize = CGSizeMake((CGRectGetWidth(self.collectionView.bounds) - 20*2) * [UIScreen mainScreen].scale, (CGRectGetHeight(self.collectionView.bounds) - 20*2) * [UIScreen mainScreen].scale);
            [imageManager requestImageForAsset:asset targetSize:targetSize contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *image, NSDictionary *info) {
                [mutableImages addObject:image];
            }];
        }

		// Assign to Array with images
        self.images = [mutableImages copy];
    }];
}

#####Swift

Import

import YangMingShan

Add delegate to your view controller

class YourViewController: UIViewController, YMSPhotoPickerViewControllerDelegate

Present default photo picker. Note it is only available for single selection

self.yms_presentAlbumPhotoViewWithDelegate(self)

Or init picker with limited photo selection of 10

let pickerViewController = YMSPhotoPickerViewController.init()
pickerViewController.numberOfPhotoToSelect = 10

With customized theme

let customColor = UIColor.init(red: 64.0/255.0, green: 0.0, blue: 144.0/255.0, alpha: 1.0)
let customCameraColor = UIColor.init(red: 86.0/255.0, green: 1.0/255.0, blue: 236.0/255.0, alpha: 1.0)

pickerViewController.theme.titleLabelTextColor = UIColor.whiteColor()
pickerViewController.theme.navigationBarBackgroundColor = customColor
pickerViewController.theme.tintColor = UIColor.whiteColor()
pickerViewController.theme.orderTintColor = customCameraColor
pickerViewController.theme.cameraVeilColor = customCameraColor
pickerViewController.theme.cameraIconColor = UIColor.whiteColor()
pickerViewController.theme.statusBarStyle = .LightContent

Present customized picker

self.yms_presentCustomAlbumPhotoView(pickerViewController, delegate: self)

Implement photoPickerViewControllerDidReceivePhotoAlbumAccessDenied(picker:) and photoPickerViewControllerDidReceiveCameraAccessDenied(picker:) to obesrve photo album and camera access denied occur

func photoPickerViewControllerDidReceivePhotoAlbumAccessDenied(_ picker: YMSPhotoPickerViewController!) {
    let alertController = UIAlertController(title: "Allow photo album access?", message: "Need your permission to access photo albums", preferredStyle: .alert)
    let dismissAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
    let settingsAction = UIAlertAction(title: "Settings", style: .default) { (action) in
        UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!)
    }
    alertController.addAction(dismissAction)
    alertController.addAction(settingsAction)

    self.present(alertController, animated: true, completion: nil)
}

func photoPickerViewControllerDidReceiveCameraAccessDenied(_ picker: YMSPhotoPickerViewController!) {
    let alertController = UIAlertController(title: "Allow camera album access?", message: "Need your permission to take a photo", preferredStyle: .alert)
    let dismissAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
    let settingsAction = UIAlertAction(title: "Settings", style: .default) { (action) in
        UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!)
    }
    alertController.addAction(dismissAction)
    alertController.addAction(settingsAction)

    // The access denied of camera is always happened on picker, present alert on it to follow the view hierarchy
    picker.present(alertController, animated: true, completion: nil)
}

Implement photoPickerViewController(picker:didFinishPickingImages:) while you expect there are mutiple photo selections

func photoPickerViewController(picker: YMSPhotoPickerViewController!, didFinishPickingImages photoAssets: [PHAsset]!) {
    // Remember images you get here is PHAsset array, you need to implement PHImageManager to get UIImage data by yourself
    picker.dismissViewControllerAnimated(true) {
        let imageManager = PHImageManager.init()
        let options = PHImageRequestOptions.init()
        options.deliveryMode = .HighQualityFormat
        options.resizeMode = .Exact
        options.synchronous = true

        let mutableImages: NSMutableArray! = []

        for asset: PHAsset in photoAssets
        {
            let scale = UIScreen.mainScreen().scale
            let targetSize = CGSizeMake((CGRectGetWidth(self.collectionView.bounds) - 20*2) * scale, (CGRectGetHeight(self.collectionView.bounds) - 20*2) * scale)
            imageManager.requestImageForAsset(asset, targetSize: targetSize, contentMode: .AspectFill, options: options, resultHandler: { (image, info) in
                    mutableImages.addObject(image!)
            })
        }
        // Assign to Array with images
        self.images = mutableImages.copy() as? NSArray
    }
}

Instruction

  • Sample Codes has been written in YangMangShanDemo project. You can read code to know about "How to implement these features in your project". Just use github to clone YangMingShan to your local disk. It should run well with your Xcode.
  • API Reference Documents > Please refer the gh-pages in YangMingShan project. We use appledoc to generate this document. The command line we generate current document is
appledoc --output {TARGET_FOLDER} --project-name "YangMingShan" --project-company "Yahoo" --company-id "com.yahoo" --no-warn-undocumented-object --keep-intermediate-files --ignore Private {YANGMINGSHAN_LOCOCAL_ROPOSITORY}

License

This software is free to use under the Yahoo Inc. BSD license. See the LICENSE for license text and copyright information.

yangmingshan's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yangmingshan's Issues

Very slow to load when a photo album has lots of photos

I noticed this when running my app (which uses YangMingShan) on a friend's phone. She has a lot of photos in her camera roll (~20000), and when I press the the button to open the photo picker, the app freezes for a good 2 seconds. I reproduced it by make 20000 copies of a uiimage on my own phone.

Is there anyway to limit the number of photos that are loaded initially and then paginate if the user ever scrolls that far?

Are the Pictures taken saved to Photos?

I was I tried selecting images that I took using the camera cell and some are not loading properly.
Is there a problem with saving the images to the phone photos? Is this possible?

Retain Selection of Images and video

Hey

I am trying to do retain of selection of images which were selected once and again when i again choose images at that time selected image i have to again select for example ,
first i choose 3 images and then again i want to add another image then i am not able to retain previous image so i have to again select those image which i had selected. Can you suggest me what should i do ?

picking 1 image issue

When picking 1 image the picker UI dismisses immediately after selection and does not invoke the delegate didFinishPickingImages handler.

        let pickerViewController = YMSPhotoPickerViewController.init()
        pickerViewController.numberOfPhotoToSelect = 1
        ...
        viewController.yms_presentCustomAlbumPhotoView(pickerViewController, delegate: self)

Customizable font use

I'd like to be able to specify font in:

  • The album cell
  • The photo cell
  • The title in the navigation bar

Not dismiss after take photo from camera.

Happen in:

  • iOS 8.4

Steps:

  1. Open photo picker.
  2. Select camera.
  3. Take picture.
  4. Press use photo => Nothing happen.

I found that delegate

  • (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo;
    not called.

It called delegate:

  • (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {}

Please check!

Selected cell count increase once more problem

HI :) , Thanks for your source code, in use, I found a problem

  1. First select a cell, and then just press the selected cell, open (YMSSinglePhotoViewController.m)
  2. Click navigationItem.rightBarButtonItem@selector (selectCurrentPhoto :), after the previously selected cell count will increase once more
  3. I think maybe need (YMSPhotoPickerViewController.m) function - (BOOL) collectionView: (UICollectionView *) collectionView shouldSelectItemAtIndexPath: (NSIndexPath *) indexPath, add a condition
    if (cell.isSelected == YES) {
        return NO;
    }

Sorry, my english is poor..... ㄒ_ㄒ

deletePhotoImage Crash!!

deletePhotoImage Crash
When I change the UICollectionViewDelegateFlowLayout code:

Changed Code
return CGSize(width: collectionView.bounds.width/4, height: collectionView.bounds.height/4)

Origin Code:
return CGSize(width: collectionView.bounds.width, height: collectionView.bounds.height)

Add an option to disable saving after taking a photo.

Hi there,
First of all, thanks for awesome project
Any chances we can add an option to disable saving function after taking a photo? For example, we don't want the photo was taken will be seen in anywhere but our application. The reason is for security.
Thank you and have a nice day :-)

Cancel button hidden

Cancel button that invokes photoPickerViewControllerDidCancel: delegate method is invisible while the YMSPhotoPickerViewController is present on screen. It is tappable and calls the corresponding delegate method properly. But it is only visible for the duration of click (tap). Look at the screenshot below to understand the scenario.
ezgif-1-8bbce1900c

PHImageManager is not working iphone4s

HI,

    for (PHAsset *asset in photoAssets) {
        CGSize targetSize = CGSizeMake((CGRectGetWidth(_mycollection.bounds) - 20*2) * [UIScreen mainScreen].scale, (CGRectGetHeight(_mycollection.bounds) - 20*2) * [UIScreen mainScreen].scale);
        [imageManager requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *image, NSDictionary *info) {
            [mutableImages addObject:image];
        }];
    } 

Th above method is not working in iphone4.suddenly it's not working.Please kindly suggest me how to resolve this issue and it is important for me.

Thanks inadvance

App crash when selecting not loaded images from iCloud.

Hey there,

Some images in picker appear completely white in picker. After looking into it, I noticed those images are not loaded from iCloud Photos yet. And when I select white image (not loaded) in picker. App crashes when I try to convert it to UIImage.

This is how I convert assets to UIImage normally.

static func getAssetImage(asset: PHAsset) -> UIImage? {
        var pickedImage: UIImage?
        let manager = PHImageManager.defaultManager()
        let option = PHImageRequestOptions()
        option.synchronous = true
        
        manager.requestImageForAsset(asset, targetSize: PHImageManagerMaximumSize, contentMode: .AspectFill, options: option) { (image: UIImage?, info: [NSObject : AnyObject]?) in
            
            pickedImage = image
        }
        
        return pickedImage
    }

Is there any way to work around this?

Navigation bar is not properly set for iPhone-X

I am using this control in my app and now for ios 11 iPhoneX i am facing problem in navigation bar as it is not properly used in iPhoneX simulator, so can it be possible to fix this issue. Thank you

UI freeze in iOS 11 iPads

Hi found an issue when using camera to take images.
Tested on iOS 11 iPad.

Steps.

  1. Open picker
  2. Press camera symbol and allow access.
  3. press cancel to go back to the picker.
  4. press cancel to go out from picker
  5. Now ui freeze about 1-8sec

Same thing happens also if you on step 3 take an image and "use photo" when it goes back to picker it will be freezing UI.
Any1 know how to fix this issue?
Thanks!

App Crash after enable photos in setting (swift 3)

I had implement library on swift 3 and app crash affer enable photos in setting with error "_BSMachError: (os/kern) invalid capability (20)" and "_BSMachError: (os/kern) invalid name (15)" . How to fix it?

Is it possible to disable the navigationController hiding on bar swipe?

I try below code; however, it doesn't seem to have any effect as there seems to be no navigationController:

pickerViewController.navigationController?.hidesBarsOnSwipe = false

navigationController is nil actually. So is there any other way to disable the hiding of the navigationBar?

Bug: Multiple Target Image Conflict

When the project has multiple targets and different images for different targets.
This repo will make all these .xcassets files lose efficacy, and all targets will use one target's images.

I have created a demo for this situation.

In init commit , everything is OK, but all install YangMingShan commit (need pod install) the app show error images.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.