Skip to content

Commit d040e85

Browse files
feat: disableImagePasting ios
1 parent 861791b commit d040e85

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export default function App() {
180180
fontWeight={'200'}
181181
fontSize={24}
182182
color="indigo"
183-
// disableImagePasting
183+
disableImagePasting={false}
184184
/>
185185
</View>
186186
<TextInput

ios/TypeRichTextInputView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
2626
- (void)invalidateTextLayoutFromCommand;
2727
- (void)updatePlaceholderVisibilityFromCommand;
2828
- (void)dispatchSelectionChangeIfNeeded;
29+
- (BOOL)isDisableImagePasting;
2930

3031
@end
3132
NS_ASSUME_NONNULL_END

ios/TypeRichTextInputView.mm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ @implementation TypeRichTextInputView {
5252
/// Commands to call from js side
5353
TypeRichTextInputCommands *_commandHandler;
5454
// BOOL _isHandlingUserInput;
55+
56+
/// Disabling Image Pasing
57+
BOOL _disableImagePasting;
5558
}
5659

5760
#pragma mark - Fabric registration
@@ -124,6 +127,8 @@ - (instancetype)initWithFrame:(CGRect)frame {
124127
_textView.font = defaultFont;
125128
_placeholderLabel.font = defaultFont;
126129

130+
_disableImagePasting = NO;
131+
127132
// Add textView as subview (not contentView)
128133
[self addSubview:_textView];
129134

@@ -301,6 +306,11 @@ - (void)updateProps:(Props::Shared const &)props
301306
);
302307
}
303308

309+
// disableImagePasting
310+
if (!oldPropsPtr || newProps.disableImagePasting != oldPropsPtr->disableImagePasting) {
311+
_disableImagePasting = newProps.disableImagePasting;
312+
}
313+
304314
#pragma mark - Style Props
305315

306316
// Text color
@@ -815,4 +825,7 @@ - (void)dispatchSelectionChangeIfNeeded {
815825
// return _isHandlingUserInput;
816826
//}
817827

828+
- (BOOL)isDisableImagePasting{
829+
return _disableImagePasting;
830+
}
818831
@end

ios/inputTextView/TypeRichUITextView.mm

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ @implementation TypeRichUITextView
1313
- (void)paste:(id)sender {
1414
UIPasteboard *pb = UIPasteboard.generalPasteboard;
1515

16-
if (pb.hasImages) {
16+
if ([self.owner isDisableImagePasting] &&
17+
pb.hasImages &&
18+
!pb.hasStrings) {
19+
return;
20+
}
21+
22+
if (
23+
![self.owner isDisableImagePasting]
24+
&& pb.hasImages
25+
) {
26+
1727
UIImage *image = pb.image;
1828
if (!image) {
1929
[super paste:sender];
@@ -53,7 +63,11 @@ - (void)paste:(id)sender {
5363

5464
- (BOOL)canPasteItemProviders:(NSArray<NSItemProvider *> *)itemProviders {
5565
for (NSItemProvider *provider in itemProviders) {
56-
if ([provider hasItemConformingToTypeIdentifier:@"public.text"] ||
66+
if ([provider hasItemConformingToTypeIdentifier:@"public.text"]) {
67+
return YES;
68+
}
69+
70+
if (![self.owner isDisableImagePasting] &&
5771
[provider hasItemConformingToTypeIdentifier:@"public.image"]) {
5872
return YES;
5973
}
@@ -65,6 +79,13 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
6579
if (action == @selector(paste:)) {
6680
UIPasteboard *pb = UIPasteboard.generalPasteboard;
6781

82+
if (
83+
[self.owner isDisableImagePasting] &&
84+
pb.hasImages &&
85+
!pb.hasStrings) {
86+
return NO;
87+
}
88+
6889
// Allow paste if there is text OR image
6990
if (pb.hasStrings || pb.hasImages) {
7091
return YES;

0 commit comments

Comments
 (0)