about summary refs log tree commit diff
path: root/patches/@mattermost+react-native-paste-input+0.8.1.patch
blob: a6d1513f153b27a4f8f3e394c90696bea50218f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
diff --git a/node_modules/@mattermost/react-native-paste-input/ios/PasteInputView.m b/node_modules/@mattermost/react-native-paste-input/ios/PasteInputView.m
index e916023..9968f3c 100644
--- a/node_modules/@mattermost/react-native-paste-input/ios/PasteInputView.m
+++ b/node_modules/@mattermost/react-native-paste-input/ios/PasteInputView.m
@@ -3,58 +3,87 @@
 //  PasteInput
 //
 //  Created by Elias Nahum on 04-11-20.
-//  Copyright © 2020 Facebook. All rights reserved.
+//  Updated to remove parent’s default text view
 //
 
 #import "PasteInputView.h"
 #import "PasteInputTextView.h"
-#import <React/RCTUtils.h>
+#import <React/RCTUtils.h> // for RCTDirectEventBlock, etc.
 
 @implementation PasteInputView
 {
-    PasteInputTextView *_backedTextInputView;
+  // We'll store the custom text view in this ivar
+  PasteInputTextView *_customBackedTextView;
 }
 
 - (instancetype)initWithBridge:(RCTBridge *)bridge
 {
+  // Must call the super’s designated initializer
   if (self = [super initWithBridge:bridge]) {
-    _backedTextInputView = [[PasteInputTextView alloc] initWithFrame:self.bounds];
-    _backedTextInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-    _backedTextInputView.textInputDelegate = self;
+    // 1. The parent (RCTMultilineTextInputView) has already created
+    //    its own _backedTextInputView = [RCTUITextView new] in super init.
+    //    We can remove that subview:
 
-    [self addSubview:_backedTextInputView];
-  }
+    id<RCTBackedTextInputViewProtocol> parentInputView = super.backedTextInputView;
+    if ([parentInputView isKindOfClass:[UIView class]]) {
+      UIView *parentSubview = (UIView *)parentInputView;
+      if (parentSubview.superview == self) {
+        [parentSubview removeFromSuperview];
+      }
+    }
 
+    // 2. Now create our custom PasteInputTextView
+    _customBackedTextView = [[PasteInputTextView alloc] initWithFrame:self.bounds];
+    _customBackedTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+    _customBackedTextView.textInputDelegate = self;
+
+    // Optional: disable inline predictions for iOS 17+
+    if (@available(iOS 17.0, *)) {
+      _customBackedTextView.inlinePredictionType = UITextInlinePredictionTypeNo;
+    }
+
+    // 3. Add your custom text view as the only subview
+    [self addSubview:_customBackedTextView];
+  }
   return self;
 }
 
+/**
+ * Override the parent's accessor so that anywhere in RN that calls
+ * `self.backedTextInputView` will get the custom PasteInputTextView.
+ */
 - (id<RCTBackedTextInputViewProtocol>)backedTextInputView
 {
-  return _backedTextInputView;
+  return _customBackedTextView;
 }
 
-- (void)setDisableCopyPaste:(BOOL)disableCopyPaste {
-    _backedTextInputView.disableCopyPaste = disableCopyPaste;
+#pragma mark - Setters for React Props
+
+- (void)setDisableCopyPaste:(BOOL)disableCopyPaste
+{
+  _customBackedTextView.disableCopyPaste = disableCopyPaste;
 }
 
-- (void)setOnPaste:(RCTDirectEventBlock)onPaste {
-    _backedTextInputView.onPaste = onPaste;
+- (void)setOnPaste:(RCTDirectEventBlock)onPaste
+{
+  _customBackedTextView.onPaste = onPaste;
 }
 
-- (void)setSmartPunctuation:(NSString *)smartPunctuation {
-    if ([smartPunctuation isEqualToString:@"enable"]) {
-        [_backedTextInputView setSmartDashesType:UITextSmartDashesTypeYes];
-        [_backedTextInputView setSmartQuotesType:UITextSmartQuotesTypeYes];
-        [_backedTextInputView setSmartInsertDeleteType:UITextSmartInsertDeleteTypeYes];
-    } else if ([smartPunctuation isEqualToString:@"disable"]) {
-        [_backedTextInputView setSmartDashesType:UITextSmartDashesTypeNo];
-        [_backedTextInputView setSmartQuotesType:UITextSmartQuotesTypeNo];
-        [_backedTextInputView setSmartInsertDeleteType:UITextSmartInsertDeleteTypeNo];
-    } else {
-        [_backedTextInputView setSmartDashesType:UITextSmartDashesTypeDefault];
-        [_backedTextInputView setSmartQuotesType:UITextSmartQuotesTypeDefault];
-        [_backedTextInputView setSmartInsertDeleteType:UITextSmartInsertDeleteTypeDefault];
-    }
+- (void)setSmartPunctuation:(NSString *)smartPunctuation
+{
+  if ([smartPunctuation isEqualToString:@"enable"]) {
+    [_customBackedTextView setSmartDashesType:UITextSmartDashesTypeYes];
+    [_customBackedTextView setSmartQuotesType:UITextSmartQuotesTypeYes];
+    [_customBackedTextView setSmartInsertDeleteType:UITextSmartInsertDeleteTypeYes];
+  } else if ([smartPunctuation isEqualToString:@"disable"]) {
+    [_customBackedTextView setSmartDashesType:UITextSmartDashesTypeNo];
+    [_customBackedTextView setSmartQuotesType:UITextSmartQuotesTypeNo];
+    [_customBackedTextView setSmartInsertDeleteType:UITextSmartInsertDeleteTypeNo];
+  } else {
+    [_customBackedTextView setSmartDashesType:UITextSmartDashesTypeDefault];
+    [_customBackedTextView setSmartQuotesType:UITextSmartQuotesTypeDefault];
+    [_customBackedTextView setSmartInsertDeleteType:UITextSmartInsertDeleteTypeDefault];
+  }
 }
 
 #pragma mark - UIScrollViewDelegate
@@ -62,7 +91,6 @@
 - (void)scrollViewDidScroll:(UIScrollView *)scrollView
 {
   RCTDirectEventBlock onScroll = self.onScroll;
-
   if (onScroll) {
     CGPoint contentOffset = scrollView.contentOffset;
     CGSize contentSize = scrollView.contentSize;
@@ -71,22 +99,22 @@
 
     onScroll(@{
       @"contentOffset": @{
-        @"x": @(contentOffset.x),
-        @"y": @(contentOffset.y)
+          @"x": @(contentOffset.x),
+          @"y": @(contentOffset.y)
       },
       @"contentInset": @{
-        @"top": @(contentInset.top),
-        @"left": @(contentInset.left),
-        @"bottom": @(contentInset.bottom),
-        @"right": @(contentInset.right)
+          @"top": @(contentInset.top),
+          @"left": @(contentInset.left),
+          @"bottom": @(contentInset.bottom),
+          @"right": @(contentInset.right)
       },
       @"contentSize": @{
-        @"width": @(contentSize.width),
-        @"height": @(contentSize.height)
+          @"width": @(contentSize.width),
+          @"height": @(contentSize.height)
       },
       @"layoutMeasurement": @{
-        @"width": @(size.width),
-        @"height": @(size.height)
+          @"width": @(size.width),
+          @"height": @(size.height)
       },
       @"zoomScale": @(scrollView.zoomScale ?: 1),
     });