Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack for scrolling #156

Conversation

skyline75489
Copy link

I'm not sure this is the correct way to do this but here it is.

Currently UIScrollView does not work. And I don't think there is a possible way for it to work. The gestureRecognizers added will conflict with those inside UIScrollView, making UIScrollView totally unusable.

So I just make it plain UIView and put together scrolling logic. This way there'll be no fancy scrollbar or bouncing, but the scrolling will work.

@migueldeicaza
Copy link
Owner

I have a branch where I did some of the work, but it has still a few bugs here and there.

#133

I agree the gesture recognizer will have to be toggled on/off under this scenario, I was tracking that here (last bullet point at the time of this writing:

#99

So I want to have a toggle on/off for the scroll events, so users can control whether they want the gestures to work, or the scrolling to work.

How are you using this scrolling if you are setting up the UIView directly? Your approach might be better than what I did. Or how are you testing it?

@skyline75489
Copy link
Author

I'm basically taking the same approach as on macOS, to manually handling scrollUp/scrollDown based on Pan gestures. Because after some experiments, I think that UIScrollView is just not suitable for a terminal app like this.

Due to the nature of UIScrollView, whatever drawRect added to the context will behave like a static picture in the background during the scrolling. UIScrollView handles all the gestures in its own implementation and does not allow us to intercept it and customize it. Ideally we want to intercept the scrolling gesture and transform it into scrollUp/Down for the terminal and then call setNeedDisplay() to refresh it. But it's just not possible. UIScrollView will always scroll things (presumably subviews) by transforming the origin.

If UIKit has NSScroller as in AppKit then we should also be able to add a scroller on the right side. But that's not the case. So I had to ditch UIScrollView entirely and just use a plain UIView. Sure it's not as smooth as UIScrollView, but it gives us more control over the behaviour of gesture handling.

As for the mouse handling on iOS, I haven't really figured it out yet. I used pan gestures for scrolling and it will conflict with the mouse events, as you can see in the code. I feel that mouse support is not as important as scrolling. Without scrolling, the terminal is not usable. Without mouse support the terminal will still be usable to most people. Besides with iOS being able to use trackpad & mouse now, handling mouse events correctly is even more harder. If it's OK I think the mouse support can be left for future work.

I'm only a person who is exploring terminals on iOS devices. Feel free to close this PR if you don't feel comfortable about it.

@migueldeicaza
Copy link
Owner

Hello!

I have implemented scrolling support now, and sorted out the conflicts between sending events vs moving around. It is a setup that works, but does not feel very iOS-ish.

It does not use the UIScrollView capability, like you point out, and that still makes me sad.

I have some comments from some months ago here: #133

The code changed since I had that branch, and I think I have a different idea of how I want to limit the rendering. I will try again that branch, which made more progress than my ill-attempted effort last night (last night I tried a quick and dirty "What if I move the terminal to a separate view", which was too dirty to work; but also found that gestures were not working, despite disabling them).

The research from last night was interesting because it did surface that there is a series of methods that UIScrollView can use to interoperate with other gesture handlers. So I will try to learn more about those ("Managing Touches" and the intro text in the documentation here: https://developer.apple.com/documentation/uikit/uiscrollview)

@migueldeicaza
Copy link
Owner

Mhm, I do like your change for scroll velocity, I will rebase tonight and try it out.

Thanks!

@skyline75489
Copy link
Author

@migueldeicaza happy to help 😃

Btw, thanks for defending the terminal devs (me included or not, doesn’t matter) on Twitter about a week ago. That was very kind of you to take your time and speak out.

@migueldeicaza
Copy link
Owner

Ok, I have implemented this in the new branch: uiscrollview-2022-07, doing some touchups before I merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants