Giter VIP home page Giter VIP logo

Comments (4)

bradleygore avatar bradleygore commented on June 4, 2024

@isaacfi - I think you'd have to look at styling options for the android TextInputLayout documentation to know what all you can control on the floating label. You're likely needing to use the hintTextAppearance attribute and XML styles as documented in the README.

Questions like this really should go on Stack Overflow - github issues are more for bug reports. 😄 Odds are, there's someone that's already ran into this and knows exactly how to style that hint text.

from nativescript-textinputlayout.

isaacfi avatar isaacfi commented on June 4, 2024

This is an issue, the problem is that hintTextApperance style cannot add margin because it is a TextAppearance Style. I implemented the lineHeight property for android in your plugin after reading this stackoverflow answer: TextInputLayout :How to give padding or margin to hint?

I share you the android code:

export const lineHeightProperty = new Property<TextInputLayout, number>({
    name: "lineHeight",
    affectsLayout: true,
    valueConverter: v => parseFloat(v)
});

private setupTextView() {
        if (!this.isLoaded) {
            return;
        }

        const textField = this._textField;
        const nativeView = this.nativeView;
        const layoutParams = new (<any>android).widget.LinearLayout.LayoutParams(
            (<any>android).widget.LinearLayout.LayoutParams.MATCH_PARENT,
            (<any>android).widget.LinearLayout.LayoutParams.WRAP_CONTENT);

        const current = nativeView.getEditText();
        const nativeTextField = textField.nativeView;
        if (current !== nativeTextField) {
            if (current) {
                nativeView.removeView(current);
            }
            if (this.lineHeight) {
                var paddingView = new (<any>android).view.View(this._context);
                const layoutParamsPaddingView = new (<any>android).widget.LinearLayout.LayoutParams(
                    (<any>android).widget.LinearLayout.LayoutParams.MATCH_PARENT,
                    this.lineHeight);
                nativeView.addView(paddingView, 0, layoutParamsPaddingView);
            }
            nativeView.addView(nativeTextField, 0, layoutParams);
        }

        // sometimes hint text isn't immediately triggered to move when navigating back to a prior view.
        // this triggers it via brute force :(
        const txtValue = textField.nativeView.getText();
        nativeTextField.setText('');
        nativeTextField.setText(txtValue);
    }

    [lineHeightProperty.setNative](value: number) {
        if (!isNaN(value)) {
            this.lineHeight = value;
        }
    }

exports.lineHeightProperty.register(TextInputLayout);

textInputLayout.android.ts.zip

Regards

from nativescript-textinputlayout.

bradleygore avatar bradleygore commented on June 4, 2024

While this may be an issue in the broader sense of the word, the aim of this component is simply parity with the native TextInputLayout component. I don't feel that doing this adding of a spacer block (the padding view) is appropriate in this level, so I'm not ready to call this an issue within the realm of this repo at this time.

What about other answers (i.e. the accepted answer) in that same thread that says that the paddingTop style on the EditText element works to accomplish this same thing? The solution you went with is near the bottom, has almost no votes, and isn't the accepted answer for the issue at hand - not sure why that one was picked over the established/accepted solution.. does the accepted one no longer work or something?

<android.support.design.widget.TextInputLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

  <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/floating_hint_margin"
    android:background="@drawable/bg_edit_text" />
</android.support.design.widget.TextInputLayout>

from nativescript-textinputlayout.

isaacfi avatar isaacfi commented on June 4, 2024

I've tested the other ones, but they depends on configuration and the padding top size would be static. Test the solution that I shared you.

Cheers

from nativescript-textinputlayout.

Related Issues (20)

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.