RCTWrapperExampleView.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import "RCTWrapperExampleView.h"
  8. #import <RCTWrapper/RCTWrapper.h>
  9. @implementation RCTWrapperExampleView {
  10. NSTimer *_timer;
  11. CGSize _intrinsicContentSize;
  12. }
  13. - (instancetype)initWithFrame:(CGRect)frame
  14. {
  15. if (self = [super initWithFrame:frame]) {
  16. self.backgroundColor = [UIColor whiteColor];
  17. _intrinsicContentSize = CGSizeMake(64, 64);
  18. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0
  19. target:self
  20. selector:@selector(tick)
  21. userInfo:nil
  22. repeats:YES];
  23. UITapGestureRecognizer *gestureRecognizer =
  24. [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tick)];
  25. [self addGestureRecognizer:gestureRecognizer];
  26. }
  27. return self;
  28. }
  29. - (void)tick
  30. {
  31. _intrinsicContentSize.width = 32 + arc4random() % 128;
  32. _intrinsicContentSize.height = 32 + arc4random() % 128;
  33. [self invalidateIntrinsicContentSize];
  34. [self.superview setNeedsLayout];
  35. }
  36. - (CGSize)intrinsicContentSize
  37. {
  38. return _intrinsicContentSize;
  39. }
  40. - (CGSize)sizeThatFits:(CGSize)size
  41. {
  42. return CGSizeMake(
  43. MIN(size.width, _intrinsicContentSize.width),
  44. MIN(size.height, _intrinsicContentSize.height)
  45. );
  46. }
  47. @end
  48. RCT_WRAPPER_FOR_VIEW(RCTWrapperExampleView)