Skip to content

Commit

Permalink
Merge pull request #150 from alanzeino/master
Browse files Browse the repository at this point in the history
Add present and dismiss commands for UIViewController
  • Loading branch information
kastiglione committed May 2, 2016
2 parents 8d31874 + 9483bb7 commit 1494846
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
31 changes: 31 additions & 0 deletions commands/FBDisplayCommands.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lldb

import fblldbviewhelpers as viewHelpers
import fblldbviewcontrollerhelpers as viewControllerHelpers
import fblldbbase as fb
import fblldbobjcruntimehelpers as runtimeHelpers

Expand All @@ -22,6 +23,8 @@ def lldbcommands():
FBUnmaskViewCommand(),
FBShowViewCommand(),
FBHideViewCommand(),
FBPresentViewControllerCommand(),
FBDismissViewControllerCommand(),
FBSlowAnimationCommand(),
FBUnslowAnimationCommand()
]
Expand Down Expand Up @@ -204,6 +207,34 @@ def run(self, args, options):
viewHelpers.setViewHidden(args[0], True)


class FBPresentViewControllerCommand(fb.FBCommand):
def name(self):
return 'present'

def description(self):
return 'Present a view controller.'

def args(self):
return [ fb.FBCommandArgument(arg='viewController', type='UIViewController *', help='The view controller to present.') ]

def run(self, args, option):
viewControllerHelpers.presentViewController(args[0])


class FBDismissViewControllerCommand(fb.FBCommand):
def name(self):
return 'dismiss'

def description(self):
return 'Dismiss a presented view controller.'

def args(self):
return [ fb.FBCommandArgument(arg='viewController', type='UIViewController *', help='The view controller to dismiss.') ]

def run(self, args, option):
viewControllerHelpers.dismissViewController(args[0])


class FBSlowAnimationCommand(fb.FBCommand):
def name(self):
return 'slowanim'
Expand Down
26 changes: 26 additions & 0 deletions fblldbviewcontrollerhelpers.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@
import fblldbbase as fb
import fblldbobjcruntimehelpers as runtimeHelpers

def presentViewController(viewController):
vc = '(%s)' % (viewController)

if fb.evaluateBooleanExpression('%s != nil && ((BOOL)[(id)%s isKindOfClass:(Class)[UIViewController class]])' % (vc, vc)):
notPresented = fb.evaluateBooleanExpression('[%s presentingViewController] == nil' % vc)

if notPresented:
lldb.debugger.HandleCommand('expr (void)[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:%s animated:YES completion:nil]' % vc)
else:
raise Exception('Argument is already presented')
else:
raise Exception('Argument must be a UIViewController')

def dismissViewController(viewController):
vc = '(%s)' % (viewController)

if fb.evaluateBooleanExpression('%s != nil && ((BOOL)[(id)%s isKindOfClass:(Class)[UIViewController class]])' % (vc, vc)):
isPresented = fb.evaluateBooleanExpression('[%s presentingViewController] != nil' % vc)

if isPresented:
lldb.debugger.HandleCommand('expr (void)[(UIViewController *)%s dismissViewControllerAnimated:YES completion:nil]' % vc)
else:
raise Exception('Argument must be presented')
else:
raise Exception('Argument must be a UIViewController')

def viewControllerRecursiveDescription(vc):
return _recursiveViewControllerDescriptionWithPrefixAndChildPrefix(fb.evaluateObjectExpression(vc), '', '', '')

Expand Down

0 comments on commit 1494846

Please sign in to comment.