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

HorizontalScrollView #48

Open
exponentialGroth opened this issue May 22, 2022 · 7 comments
Open

HorizontalScrollView #48

exponentialGroth opened this issue May 22, 2022 · 7 comments

Comments

@exponentialGroth
Copy link

I noticed that there is a vertical scrollview already implemented in this MathView. Is horizontal scrolling possible too?
I played around with tons of parameters but I couldn't figure out how to achieve horizontal scrolling. Unfortunately, putting the MathView in a HorizontalScrollView didn't seem to work neither.
I can see a horizontal scrollbar if I press the plus or minus sign that shows up during vertical scrolling, but the scrollbar and the text don't move.

Any working examples or advice appreciated.

@Aiosa
Copy link

Aiosa commented May 22, 2022

It's just a WebView. See the web view API. The vertical scroll works for you because the content overflows the browser container height, that's all. It's just a HTML. Of course putting it inside scrollable element does not work because the WebView is a fixed size. The interaction happens inside. Browse closed issues here on examples on how to work with WebView...#47 . Similar code will help you with scrolling. Of course, if your content does not overflow horizontally, the slider will not show up (Idk how much CSS support is in there, I feel like I saw somewhere WebView being discontinued).

@exponentialGroth
Copy link
Author

exponentialGroth commented May 22, 2022

Ok, trying HorizontalScrollView was indeed a bit dumb. But the rest is a bit more complicated.
At first, the vertical scrolling only works if the width is big enough (independent of the height, idk why).

Secondly, I discovered that horizontal scrolling works when I measure the width of the MathView everytime I set the text:

val displayMetrics: DisplayMetrics = resources.displayMetrics
this.measure(0, 0)
val x = this.measuredWidth/displayMetrics.density
Log.println(Log.ASSERT, "Calc", x.toString())

this is the mathView (I made my own setText function).
But there is a big problem. Whenever the MathView reaches a certain width it gets bigger and bigger and than the application crashes, like in that video:

scroll_example.mp4

mVDisplay2.settings.useWideViewPort = true makes that width bigger, but it happens nontheless.

The first line of the stacktrace: A/art: art/runtime/java_vm_ext.cc:470] JNI DETECTED ERROR IN APPLICATION: JNI CallObjectMethod called with pending exception java.lang.IllegalStateException: Unable to create layer for MathView, size 17769x140 exceeds max size 16384

Do you have an idea why this happens? And why has measuring something to do with the ability to scroll? Thank you

Edit: On my physical device (API 31, the virtual one is 25) it seems to get bigger too but it does not crash.

@Aiosa
Copy link

Aiosa commented May 22, 2022

Sorry, no idea and no don't have time to investigate either. The measuring makes WebView update its viewport I guess so it calls some function that does the update.
Judging from the video, it is not 'certain width' but once the viewport is forced to scroll, it for some reason starts allocation of needless stuff and expands more than it should - creates many instances of some layer it uses to render things on. I would try to get rid of things in your code you are not sure about what they really do (I am pretty sure you have some of those 😅)... Usually, such things are caused by misunderstanding of the API. Run profiler on it to see what function cycles since it fails on memory allocation (that's the message), your physical device has more hardware specs to withstand it I guess.

@Aiosa
Copy link

Aiosa commented May 22, 2022

One wild guess is that it might be the problem of the rendering script, I don't know how you update the contents but safest would be to try to 'reload the whole page' on content update (re-initalize the page) and see whether it solves the problem for you

@exponentialGroth
Copy link
Author

That makes sense. Thank you for your answers and the amount of time you spent, I'll try to find the exact sources or a way to work around the problem. Should I close the issue now or when I've found the solution? I'm not very familiar with the rules on gitHub

@Aiosa
Copy link

Aiosa commented May 22, 2022

Once you've found the fix/workaround

@exponentialGroth
Copy link
Author

exponentialGroth commented May 23, 2022

Haven't found the solution yet (gotta go to school now, but I hope I find one after), but I think I identified the exact problem.
That's an image of the lifecycle of a view.

And this happens when calling setDisplayText():

public void setDisplayText(String formula_text) {
    this.display_text = formula_text;
    loadData();
  }
  private void loadData()
  {
    if (this.display_text!=null)
    {
      this.loadDataWithBaseURL("null",getOfflineKatexConfig(),"text/html","UTF-8","about:blank");
    }

  }

Loaddata seems to act like invalidate(), which makes sense, because normally invalidate is called when the text or color should change, but not the size. So I think I need to call something like requestLayout(), because the size changes. That's why it worked a bit with calling measure().

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

No branches or pull requests

2 participants