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 Wix. 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. #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
  14. - (id)__swz_initWithEventDispatcher:(id)eventDispatcher
  15. {
  16. id returnValue = __SWZ_initWithEventDispatcher_orig(self, _cmd, eventDispatcher);
  17. if (@available(iOS 11.0, *)) {
  18. [(UIScrollView*)[returnValue valueForKey:@"scrollView"] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAlways];
  19. }
  20. return returnValue;
  21. }
  22. + (void)load
  23. {
  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