GithubHelp home page GithubHelp logo

Why infinity loop? about textlayoutbuilder HOT 4 CLOSED

facebook avatar facebook commented on April 20, 2024
Why infinity loop?

from textlayoutbuilder.

Comments (4)

ahmedre avatar ahmedre commented on April 20, 2024

the infinite loop is a workaround for this bug, so that if the IndexOutOfBoundsException is thrown, we can remove the spans and try again. it's possible to re-write this with a method instead (and just re-call the method without the Spannables in the IndexOutOfBounds scenario, but that's not much nicer either).

is there any specific issue your'e running into with this? this should never actually infinite loop (due to the break when no exception is thrown, a single loop if an IndexOutOfBoundsException is thrown and we are in the spannable case, or an exception being bubbled up).

from textlayoutbuilder.

MkhytarMkhoian avatar MkhytarMkhoian commented on April 20, 2024

Ok, then better remove loop, because it's confused

 try {
      layout = makeStaticLayout(numLines, width);
          
        } catch (IndexOutOfBoundsException e) {
          // Workaround for https://code.google.com/p/android/issues/detail?id=35412
          if (!(mParams.text instanceof String)) {
            // remove all Spannables and re-try
            Log.e("TextLayoutBuilder", "Hit bug #35412, retrying with Spannables removed", e);
            mParams.text = mParams.text.toString();
            layout = makeStaticLayout(numLines, width);

          } else {
            // If it still happens with all Spannables removed we'll bubble the exception up
            throw e;
          }
        }

private StaticLayout makeStaticLayout(int numLines, int width) {
    return StaticLayoutHelper.make(
        mParams.text,
        0,
        mParams.text.length(),
        mParams.paint,
        width,
        mParams.alignment,
        mParams.spacingMult,
        mParams.spacingAdd,
        mParams.includePadding,
        mParams.ellipsize,
        width,
        numLines,
        mParams.textDirection);
  }

from textlayoutbuilder.

MkhytarMkhoian avatar MkhytarMkhoian commented on April 20, 2024

If you try the workaround for a bug on some Android API version, then better to check current API version, because current solution is not optimal.

from textlayoutbuilder.

sriramramani avatar sriramramani commented on April 20, 2024

Can you please send in a pull request? Closing this for now.

from textlayoutbuilder.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.