Flutter Engine
 
Loading...
Searching...
No Matches
TextPlatformView.m
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import "TextPlatformView.h"
6
7@protocol TestGestureRecognizerDelegate <NSObject>
8
9- (void)gestureTouchesBegan;
10- (void)gestureTouchesEnded;
11
12@end
13
14@interface TestTapGestureRecognizer : UITapGestureRecognizer
15
16@property(weak, nonatomic)
17 NSObject<TestGestureRecognizerDelegate>* testTapGestureRecognizerDelegate;
18
19@end
20
21@implementation TestTapGestureRecognizer
22
23- (void)touchesBegan:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
24 [self.testTapGestureRecognizerDelegate gestureTouchesBegan];
25 [super touchesBegan:touches withEvent:event];
26}
27
28- (void)touchesEnded:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
29 [self.testTapGestureRecognizerDelegate gestureTouchesEnded];
30 [super touchesEnded:touches withEvent:event];
31}
32
33@end
34
35@implementation TextPlatformViewFactory {
36 NSObject<FlutterBinaryMessenger>* _messenger;
37}
38
39- (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
40 self = [super init];
41 if (self) {
42 _messenger = messenger;
43 }
44 return self;
45}
46
47- (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
48 viewIdentifier:(int64_t)viewId
49 arguments:(id _Nullable)args {
50 TextPlatformView* textPlatformView = [[TextPlatformView alloc] initWithFrame:frame
51 viewIdentifier:viewId
52 arguments:args
53 binaryMessenger:_messenger];
54 return textPlatformView;
55}
56
57- (NSObject<FlutterMessageCodec>*)createArgsCodec {
59}
60
61@end
62
63@interface TextPlatformView () <TestGestureRecognizerDelegate>
64
65@end
66
67@implementation TextPlatformView {
68 UIView* _containerView;
69 UITextView* _textView;
72}
73
74- (instancetype)initWithFrame:(CGRect)frame
75 viewIdentifier:(int64_t)viewId
76 arguments:(id _Nullable)args
77 binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
78 self = [super init];
79 if (self) {
80 _containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 100)];
81 _containerView.backgroundColor = UIColor.lightGrayColor;
82 _containerView.clipsToBounds = YES;
83 _containerView.accessibilityIdentifier = @"platform_view";
84
85 _textView = [[UITextView alloc] initWithFrame:CGRectMake(50.0, 50.0, 250, 100)];
86 _textView.backgroundColor = UIColor.lightGrayColor;
87 _textView.textColor = UIColor.blueColor;
88 [_textView setFont:[UIFont systemFontOfSize:52]];
89 _textView.text = args;
90 _textView.autoresizingMask =
91 (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
92 [_containerView addSubview:_textView];
93
94 TestTapGestureRecognizer* gestureRecognizer =
95 [[TestTapGestureRecognizer alloc] initWithTarget:self action:@selector(platformViewTapped)];
96
97 [_textView addGestureRecognizer:gestureRecognizer];
98 gestureRecognizer.testTapGestureRecognizerDelegate = self;
99
100 _textView.accessibilityLabel = @"";
101
102 _viewCreated = NO;
103 }
104 return self;
105}
106
107- (UIView*)view {
108 // Makes sure the engine only calls this method once.
109 if (_viewCreated) {
110 abort();
111 }
112 _viewCreated = YES;
113 return _containerView;
114}
115
116- (void)platformViewTapped {
117 _textView.accessibilityLabel =
118 [_textView.accessibilityLabel stringByAppendingString:@"-platformViewTapped"];
119}
120
121- (void)gestureTouchesBegan {
122 _textView.accessibilityLabel =
123 [_textView.accessibilityLabel stringByAppendingString:@"-gestureTouchesBegan"];
124}
125
126- (void)gestureTouchesEnded {
127 _textView.accessibilityLabel =
128 [_textView.accessibilityLabel stringByAppendingString:@"-gestureTouchesEnded"];
129}
130
131@end
FlutterMethodChannel * _channel
BOOL _viewCreated
UITextView * _textView
FlView * view
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
NSObject< TestGestureRecognizerDelegate > * testTapGestureRecognizerDelegate
instancetype initWithFrame
instancetype sharedInstance()
int BOOL