react-native-selectable-text icon indicating copy to clipboard operation
react-native-selectable-text copied to clipboard

onHighlightPress property is not working on IOS OS 16+

Open react3-moon opened this issue 2 years ago • 10 comments
trafficstars

onHighlightPress property is not working on IOS OS 16+

    "react": "17.0.2",
    "react-native": "0.67.2",
    "@alentoma/react-native-selectable-text": "1.6.0",

below mentioned code always return 0 for clickedRangeStart & clickedRangeEnd.

-(void) handleSingleTap: (UITapGestureRecognizer *) gesture
{
    CGPoint pos = [gesture locationInView:_backedTextInputView];
    pos.y += _backedTextInputView.contentOffset.y;
    
    UITextPosition *tapPos = [_backedTextInputView closestPositionToPoint:pos];
    UITextRange *word = [_backedTextInputView.tokenizer rangeEnclosingPosition:tapPos withGranularity:(UITextGranularityWord) inDirection:UITextLayoutDirectionRight];
    
    UITextPosition* beginning = _backedTextInputView.beginningOfDocument;
    
    UITextPosition *selectionStart = word.start;
    UITextPosition *selectionEnd = word.end;
    
    const NSInteger location = [_backedTextInputView offsetFromPosition:beginning toPosition:selectionStart];
    const NSInteger endLocation = [_backedTextInputView offsetFromPosition:beginning toPosition:selectionEnd];
    
    self.onHighlightPress(@{
        @"clickedRangeStart": @(location),
        @"clickedRangeEnd": @(endLocation),
    });
}

@AlenToma

react3-moon avatar Jan 16 '23 07:01 react3-moon

Sadly I dont own IOS or mac so I can't fix this if it is really an issue.

But no body have complained about this so I dont know if the issue is really with the library.

If someone could test this?

AlenToma avatar Jan 16 '23 13:01 AlenToma

I am also facing the same issue. is any one have luck?

Harshkansaramoon avatar Jan 17 '23 13:01 Harshkansaramoon

I have build another library may be as a replacement.

https://github.com/AlenToma/react-native-text-contextmenu

AlenToma avatar Jan 18 '23 10:01 AlenToma

@AlenToma thank you for your support. for now I changed in native library code of your and I replace this line UITextRange *word = [_backedTextInputView.tokenizer rangeEnclosingPosition:tapPos withGranularity:(UITextGranularityWord) inDirection: inDirection:UITextLayoutDirectionRight]; to UITextRange *word = [_backedTextInputView.tokenizer rangeEnclosingPosition:tapPos withGranularity:(UITextGranularityWord) inDirection:UITextWritingDirectionNatural];

and its work for me in all versions of IOS.

Harshkansaramoon avatar Jan 18 '23 10:01 Harshkansaramoon

Hey im facing issue with selection text on higher version of IOS lower versions are working fine

@Harshkansaramoon can you please let me know which file did you updated for the fix?

ZainabShakeel avatar Feb 02 '23 09:02 ZainabShakeel

@ZainabShakeel in this I changed file RNSelectableTextView.m

Harshkansaramoon avatar Feb 02 '23 10:02 Harshkansaramoon

yes found @Harshkansaramoon Thanks a lot.

ZainabShakeel avatar Feb 02 '23 10:02 ZainabShakeel

@Harshkansaramoon Have you got app crash when long press a word and swipe right ?whether some new feature update caused this issue on ios 16?

Bourne007-13 avatar Feb 20 '23 09:02 Bourne007-13

@Harshkansaramoon could you check in your version of the fix and I will do pull and publish it.

AlenToma avatar Feb 20 '23 15:02 AlenToma

Hi, we have implemented https://www.npmjs.com/package/@vandrei977/react-native-selectable-text and that is forked from this library. We are not getting any crash.

react3-moon avatar Feb 21 '23 08:02 react3-moon