Ejemplo n.º 1
0
        private static void HandleTap(UITapGestureRecognizer gestureRecognizer, UITextView textView, Dictionary <Source, FinalSourcePosition> sourcePositions, IInteractiveSourceAction action)
        {
            var point = gestureRecognizer.LocationInView(textView);

            point.Y += textView.ContentOffset.Y;

            var tapPos = textView.GetClosestPositionToPoint(point);

            // if a source link has been tapped: show the reference
            nint clickedPos    = textView.GetOffsetFromPosition(textView.BeginningOfDocument, tapPos);
            int  pos           = Convert.ToInt32(clickedPos);
            var  clickedSource = sourcePositions.SingleOrDefault(x => x.Value.Start <= pos && pos <= x.Value.End).Key;

            if (clickedSource != null)
            {
                action.Display(clickedSource);
            }
        }
Ejemplo n.º 2
0
        private void Tap(UITapGestureRecognizer tap)
        {
            var location = tap.LocationInView(Control);
            // Fale UseTextView
            var fakeTextViwe = new UITextView(Control.Frame);

            fakeTextViwe.TextContainer.LineFragmentPadding = 0;
            fakeTextViwe.TextContainerInset = UIEdgeInsets.Zero;
            fakeTextViwe.AttributedText     = Control.AttributedText;
            var selectedPositon = fakeTextViwe.GetClosestPositionToPoint(location);
            var position        = (int)fakeTextViwe.GetOffsetFromPosition(fakeTextViwe.BeginningOfDocument, selectedPositon);

            var label = Element as Shared.LinkerLabel;

            if (label.MatchWords.Any(x => x.StartPosition <= position && x.EndPositon >= position))
            {
                var word = label.MatchWords.First(x => x.StartPosition <= position && x.EndPositon >= position);
                if (label.Command?.CanExecute(word.Word) == true)
                {
                    label.Command.Execute(word.Word);
                }
            }
        }
Ejemplo n.º 3
0
        protected void OnTapUrl(UIGestureRecognizer tap)
        {
            var location = tap.LocationInView(Control);
            var textView = new UITextView(Control.Frame);

            textView.TextContainer.LineFragmentPadding = 0;
            textView.TextContainerInset = UIEdgeInsets.Zero;
            textView.AttributedText     = Control.AttributedText;

            var position = textView.GetOffsetFromPosition(
                textView.BeginningOfDocument,
                textView.GetClosestPositionToPoint(location)
                );

            var url = this.Matches.FirstOrDefault(m =>
                                                  m.Index <= position && position <= (m.Index + m.Length)
                                                  );

            if (url != null)
            {
                UIApplication.SharedApplication.OpenUrl(new Uri(url.Value));
            }
        }