XCUIElement+FBForceTouch.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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+FBForceTouch.h"
  10. #if !TARGET_OS_TV
  11. #import "FBErrorBuilder.h"
  12. #import "XCUICoordinate.h"
  13. #import "XCUIDevice.h"
  14. @implementation XCUIElement (FBForceTouch)
  15. - (BOOL)fb_forceTouchCoordinate:(NSValue *)relativeCoordinate
  16. pressure:(NSNumber *)pressure
  17. duration:(NSNumber *)duration
  18. error:(NSError **)error
  19. {
  20. if (![XCUIDevice sharedDevice].supportsPressureInteraction) {
  21. return [[[FBErrorBuilder builder]
  22. withDescriptionFormat:@"Force press is not supported on this device"]
  23. buildError:error];
  24. }
  25. if (nil == relativeCoordinate) {
  26. if (nil == pressure || nil == duration) {
  27. [self forcePress];
  28. } else {
  29. [self pressWithPressure:[pressure doubleValue] duration:[duration doubleValue]];
  30. }
  31. } else {
  32. CGVector offset = CGVectorMake(relativeCoordinate.CGPointValue.x,
  33. relativeCoordinate.CGPointValue.y);
  34. XCUICoordinate *hitPoint = [[self coordinateWithNormalizedOffset:CGVectorMake(0, 0)]
  35. coordinateWithOffset:offset];
  36. if (nil == pressure || nil == duration) {
  37. [hitPoint forcePress];
  38. } else {
  39. [hitPoint pressWithPressure:[pressure doubleValue] duration:[duration doubleValue]];
  40. }
  41. }
  42. return YES;
  43. }
  44. @end
  45. #endif