Shelly: Added UIView helpers to help detect if a view is animating #81

Merged
merged 1 commit into from Mar 20, 2012

2 participants

@mhaylock

I ran into an issue where interacting with UIAlertView's was happening too fast (i.e. before the view finished animating) - in this particular case one UIAlertView would show another, but the still active animation of the previous alert view prevented it from showing.

Putting in a sleep worked but I wanted a faster solution. By adding a isNotAnimating selector to UIView I can now filter by this.

My alert view steps (based on the code in this pull request which hasn't been merged in) now look like this:

WAIT_TIMEOUT = ENV['WAIT_TIMEOUT'].to_i || 240

Given /^I (do not )?see an alert view titled "([^\"]*)"$/ do |qualifier, expected_mark|
  expected_to_see = "do not " != qualifier

  values = []
  Timeout::timeout(WAIT_TIMEOUT) do
    until !(values = frankly_map( 'alertView isNotAnimating', 'title')).empty?
      sleep 0.1
    end
  end

  if expected_to_see
    values.should include(expected_mark)
  else
    values.should_not include(expected_mark)
  end
end

Given /^I (do not )?see an alert view with the message "([^\"]*)"$/ do |qualifier, expected_mark|
  expected_to_see = "not " != qualifier

  values = []
  Timeout::timeout(WAIT_TIMEOUT) do
    until !(values = frankly_map( 'alertView isNotAnimating', 'message')).empty?
      sleep 0.1
    end
  end

  if expected_to_see
    values.should include(expected_mark)
  else
    values.should_not include(expected_mark)
  end
end

This change solves my problem - the code find the alert view the moment it stops animating. I suspect this pattern of waiting for a view to stop animating will be something I return to more than once as this first project using Frank grows.

@mhaylock mhaylock Added UIView helpers isAnimating and isNotAnimating to help filter ou…
…t views that are still in animation when necessary.
620100a
@moredip
Owner

This is awesome. Thanks Mark.

@moredip moredip merged commit 9144416 into moredip:master Mar 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment