1/*
2 * Copyright (c) Meta Platforms, Inc. and 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
8#import "ABI48_0_0RCTWrapperExampleView.h"
9
10#import <ABI48_0_0RCTWrapper/ABI48_0_0RCTWrapper.h>
11
12@implementation ABI48_0_0RCTWrapperExampleView {
13  NSTimer *_timer;
14  CGSize _intrinsicContentSize;
15}
16
17- (instancetype)initWithFrame:(CGRect)frame
18{
19  if (self = [super initWithFrame:frame]) {
20    self.backgroundColor = [UIColor whiteColor];
21
22    _intrinsicContentSize = CGSizeMake(64, 64);
23    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(tick) userInfo:nil repeats:YES];
24
25    UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
26                                                                                        action:@selector(tick)];
27    [self addGestureRecognizer:gestureRecognizer];
28  }
29  return self;
30}
31
32- (void)tick
33{
34  _intrinsicContentSize.width = 32 + arc4random() % 128;
35  _intrinsicContentSize.height = 32 + arc4random() % 128;
36
37  [self invalidateIntrinsicContentSize];
38  [self.superview setNeedsLayout];
39}
40
41- (CGSize)intrinsicContentSize
42{
43  return _intrinsicContentSize;
44}
45
46- (CGSize)sizeThatFits:(CGSize)size
47{
48  return CGSizeMake(MIN(size.width, _intrinsicContentSize.width), MIN(size.height, _intrinsicContentSize.height));
49}
50
51@end
52
53ABI48_0_0RCT_WRAPPER_FOR_VIEW(ABI48_0_0RCTWrapperExampleView)
54