Skip to content
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

Callback when a side is about to open #77

Closed
jonasman opened this issue Aug 14, 2013 · 6 comments
Closed

Callback when a side is about to open #77

jonasman opened this issue Aug 14, 2013 · 6 comments

Comments

@jonasman
Copy link

Hi,

Is there any callback when a side view is about to open.
I saw that there is one when the side was completely open. But not when it will open.

DidOpen:
-(void)setGestureCompletionBlock:(void(^)(MMDrawerController * drawerController, UIGestureRecognizer * gesture))gestureCompletionBlock;

Also should this callbacks be made via a delegate as any other VC?

@jonasman
Copy link
Author

Also there is no call back when a side is about to Close.

@kcharwood
Copy link
Contributor

This might be a good case for subclassing. I could expose these methods in #37, and you can override them and call super, and do what you need to do in that case.

@kcharwood
Copy link
Contributor

I just added the open/close methods to c178e4d. That should get you the behavior you need, or at least the hooks to build out whatever behavior you need.

@jonasman
Copy link
Author

It doesn't look so nice.

So i need to subclass to get the WillOpen/close but to get the DidOpen/Close i just pass a block.
Shouldn't it be all blocks? or all delegate calls?

@kcharwood
Copy link
Contributor

It's a tough call @jonasman .

For now, I'd like to keep it in the subclass. If it becomes a popular enough feature, we could look to extend the public interface to provide another block. By opening up the method to subclass, it at least provides you a way to get the behavior you are looking for.

I don't want to take in every single feature request when they first come up to keep the public interface as light as possible.

@jonasman
Copy link
Author

Hi,

I just realize the new subclass is not working 100% to fullfill this purpuse:

My code:

-(void)prepareToPresentDrawer:(MMDrawerSide)drawer animated:(BOOL)animated
{
    NSLog(@"Prepare");
    [super prepareToPresentDrawer:drawer animated:animated];

    if ([self.delegate respondsToSelector:@selector(MMDrawer:WillOpenSide:)])
    [self.delegate MMDrawer:self WillOpenSide:drawer];

}

-(void)openDrawerSide:(MMDrawerSide)drawerSide
           animated:(BOOL)animated
            velocity:(CGFloat)velocity
     animationOptions:(UIViewAnimationOptions)options
         completion:(void (^)(BOOL))completion
 {

        NSLog(@"Open");
    __typeof(self) __weak weakSelf = self;

    void (^newCompletion)(BOOL) = ^void (BOOL finished){
        if ([weakSelf.delegate respondsToSelector:@selector(MMDrawer:DidOpenSide:)])
            [weakSelf.delegate MMDrawer:weakSelf DidOpenSide:drawerSide];
        NSLog(@"Open complete");
        if (completion)
             completion(finished);
    };

    [super openDrawerSide:drawerSide animated:animated velocity:velocity animationOptions:options completion:newCompletion];

 }

-(void)closeDrawerAnimated:(BOOL)animated
              velocity:(CGFloat)velocity
      animationOptions:(UIViewAnimationOptions)options
            completion:(void (^)(BOOL))completion
{
         NSLog(@"Close");
    if ([self.delegate respondsToSelector:@selector(MMDrawerWillClose:)])
        [self.delegate MMDrawerWillClose:self];



    __typeof(self) __weak weakSelf = self;

    void (^newCompletion)(BOOL) = ^void (BOOL finished){
        if ([weakSelf.delegate respondsToSelector:@selector(MMDrawerDidClose:)])
            [weakSelf.delegate MMDrawerDidClose:weakSelf];

        NSLog(@"close complete");
        if (completion)
           completion(finished);
    };

    [super closeDrawerAnimated:animated velocity:velocity animationOptions:options completion:newCompletion];
}

There is one case that it wont show "close" when i pan the center to the left completly the close method is not called thus i dont know that it has closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants