react-native-navigation的迁移库

RNNSwizzles.m 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // RNNSwizzles.m
  3. // ReactNativeNavigation
  4. //
  5. // Created by Leo Natan (Wix) on 1/17/18.
  6. // Copyright © 2018 artal. All rights reserved.
  7. //
  8. #import "RNNSwizzles.h"
  9. @import ObjectiveC;
  10. @import UIKit;
  11. static id (*__SWZ_initWithEventDispatcher_orig)(id self, SEL _cmd, id eventDispatcher);
  12. @implementation RNNSwizzles
  13. - (id)__swz_initWithEventDispatcher:(id)eventDispatcher
  14. {
  15. id returnValue = __SWZ_initWithEventDispatcher_orig(self, _cmd, eventDispatcher);
  16. if (@available(iOS 11.0, *)) {
  17. [(UIScrollView*)[returnValue valueForKey:@"scrollView"] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAutomatic];
  18. }
  19. return returnValue;
  20. }
  21. + (void)applySwizzles
  22. {
  23. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
  24. Class cls = NSClassFromString(@"RCTScrollView");
  25. if(cls == NULL)
  26. {
  27. return;
  28. }
  29. Method m1 = class_getInstanceMethod(cls, NSSelectorFromString(@"initWithEventDispatcher:"));
  30. if(m1 == NULL)
  31. {
  32. return;
  33. }
  34. __SWZ_initWithEventDispatcher_orig = (void*)method_getImplementation(m1);
  35. Method m2 = class_getInstanceMethod([RNNSwizzles class], NSSelectorFromString(@"__swz_initWithEventDispatcher:"));
  36. method_exchangeImplementations(m1, m2);
  37. }
  38. #endif
  39. @end