Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TextPlatformView.m
Go to the documentation of this file.
1// Copyright 2018 The Chromium 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
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
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 if ([super init]) {
79 _containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 100)];
80 _containerView.backgroundColor = UIColor.lightGrayColor;
81 _containerView.clipsToBounds = YES;
82 _containerView.accessibilityIdentifier = @"platform_view";
83
84 _textView = [[UITextView alloc] initWithFrame:CGRectMake(50.0, 50.0, 250, 100)];
85 _textView.backgroundColor = UIColor.lightGrayColor;
86 _textView.textColor = UIColor.blueColor;
87 [_textView setFont:[UIFont systemFontOfSize:52]];
88 _textView.text = args;
89 _textView.autoresizingMask =
90 (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
91 [_containerView addSubview:_textView];
92
93 TestTapGestureRecognizer* gestureRecognizer =
94 [[TestTapGestureRecognizer alloc] initWithTarget:self action:@selector(platformViewTapped)];
95
96 [_textView addGestureRecognizer:gestureRecognizer];
97 gestureRecognizer.testTapGestureRecognizerDelegate = self;
98
99 _textView.accessibilityLabel = @"";
100
101 _viewCreated = NO;
102 }
103 return self;
104}
105
106- (UIView*)view {
107 // Makes sure the engine only calls this method once.
108 if (_viewCreated) {
109 abort();
110 }
111 _viewCreated = YES;
112 return _containerView;
113}
114
115- (void)platformViewTapped {
116 _textView.accessibilityLabel =
117 [_textView.accessibilityLabel stringByAppendingString:@"-platformViewTapped"];
118}
119
120- (void)gestureTouchesBegan {
121 _textView.accessibilityLabel =
122 [_textView.accessibilityLabel stringByAppendingString:@"-gestureTouchesBegan"];
123}
124
125- (void)gestureTouchesEnded {
126 _textView.accessibilityLabel =
127 [_textView.accessibilityLabel stringByAppendingString:@"-gestureTouchesEnded"];
128}
129
130@end
FlutterMethodChannel * _channel
BOOL _viewCreated
UITextView * _textView
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
instancetype sharedInstance()
NSObject< TestGestureRecognizerDelegate > * testTapGestureRecognizerDelegate
instancetype initWithFrame
static bool init()
int BOOL
Definition: windows_types.h:37