XCUIElement+FBSwiping.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "XCUIElement+FBSwiping.h"
  10. #import "FBLogger.h"
  11. #import "XCUIElement.h"
  12. void swipeWithDirection(NSObject *target, NSString *direction, NSNumber* _Nullable velocity) {
  13. double velocityValue = .0;
  14. if (nil != velocity) {
  15. velocityValue = [velocity doubleValue];
  16. }
  17. if (velocityValue > 0) {
  18. SEL selector = NSSelectorFromString([NSString stringWithFormat:@"swipe%@WithVelocity:",
  19. direction.lowercaseString.capitalizedString]);
  20. NSMethodSignature *signature = [target methodSignatureForSelector:selector];
  21. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
  22. [invocation setSelector:selector];
  23. [invocation setArgument:&velocityValue atIndex:2];
  24. [invocation invokeWithTarget:target];
  25. } else {
  26. SEL selector = NSSelectorFromString([NSString stringWithFormat:@"swipe%@",
  27. direction.lowercaseString.capitalizedString]);
  28. NSMethodSignature *signature = [target methodSignatureForSelector:selector];
  29. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
  30. [invocation setSelector:selector];
  31. [invocation invokeWithTarget:target];
  32. }
  33. }
  34. @implementation XCUIElement (FBSwiping)
  35. - (void)fb_swipeWithDirection:(NSString *)direction velocity:(nullable NSNumber*)velocity
  36. {
  37. swipeWithDirection(self, direction, velocity);
  38. }
  39. @end
  40. #if !TARGET_OS_TV
  41. @implementation XCUICoordinate (FBSwiping)
  42. - (void)fb_swipeWithDirection:(NSString *)direction velocity:(nullable NSNumber*)velocity
  43. {
  44. swipeWithDirection(self, direction, velocity);
  45. }
  46. @end
  47. #endif