NativeScript / theme

@nativescript/theme
https://v7.docs.nativescript.org/ui/theme
Apache License 2.0
127 stars 44 forks source link

RadDatForm styling is not working #260

Open jmdavid opened 4 years ago

jmdavid commented 4 years ago

In my project, I use themes:

@import "~@nativescript/theme/core";

In one of my components, I use RadDataForm. For picker input, the arrow is hidden. I cannot apply TKPropertyEditorStyle, it is ignored completely.

<TKEntityProperty tkDataFormProperty name="name" displayName="Name" index="0>
     <TKPropertyEditor tkEntityPropertyEditor type="Text">
        <TKPropertyEditorStyle tkPropertyEditorStyle strokeColor="#00695c" strokeWidth="2" fillColor="#4db6ac" labelHidden="false"
                labelTextSize="18" ios:labelFontName="Times New Roman" android:labelFontName="sans-serif-light" labelFontStyle="Italic"
                labelPosition="Top" labelTextColor="#00695c">
        </TKPropertyEditorStyle>
    </TKPropertyEditor>
</TKEntityProperty>

nsbug

If I import compat (@import "~@nativescript/theme/core.compat";), it works.

So there is an incompatibility with new themes and Rad component. How can I fix it without using old compat (that makes my app ugly)?

Thanks.

jmdavid commented 4 years ago

Here are the steps to reproduce.

> tns create bugng --template tns-template-drawer-navigation-ng
    found 6 vulnerabilities (5 moderate, 1 high)
> npm audit fix
    3 vulnerabilities required manual review and could not be updated
    1 package update for 1 vulnerability involved breaking changes
> npm audit fix --force
> tns plugin add nativescript-ui-dataform

Then, in app.module.ts, added:

import { NativeScriptFormsModule } from "nativescript-angular/forms";
  ...
  imports: [
    ...
    NativeScriptFormsModule
  ]

Then, in home.module.ts, added:

import { NativeScriptUIDataFormModule } from "nativescript-ui-dataform/angular";
  ...
  imports: [
    ...
    NativeScriptUIDataFormModule
  ]

home.component.ts :

import { Component, OnInit, ViewChild } from "@angular/core";
import { RadSideDrawer } from "nativescript-ui-sidedrawer";
import * as app from "tns-core-modules/application";
import { RadDataFormComponent } from "nativescript-ui-dataform/angular/dataform-directives";

@Component({
    selector: "Home",
    templateUrl: "./home.component.html"
})
export class HomeComponent implements OnInit {

    @ViewChild('myCommitDataForm', { static: false }) myCommitDataFormComp: RadDataFormComponent;
    private _person: Person;

    constructor() {
        // Use the component constructor to inject providers.
    }

    ngOnInit(): void {
        this._person = new Person("John", 23, "john@company.com", -1);
    }

    onDrawerButtonTap(): void {
        const sideDrawer = <RadSideDrawer>app.getRootView();
        sideDrawer.showDrawer();
    }

    public onPropertyCommitted(args) {
        console.log(args.propertyName);
        if (this.myCommitDataFormComp.dataForm.editedObject) {
            console.log(this.myCommitDataFormComp.dataForm.editedObject);
        }
    }

    get person(): Person {
        return this._person;
    }
}

class Person {
    constructor(public name: string, public age: number, public email: string, public city?: number) { }
}

home.component.html :

<ActionBar>
    <NavigationButton ios:visibility="collapsed" icon="res://menu" (tap)="onDrawerButtonTap()"></NavigationButton>
    <ActionItem icon="res://menu" android:visibility="collapsed" (tap)="onDrawerButtonTap()"
        ios.position="left">
    </ActionItem>
    <Label text="Home"></Label>
</ActionBar>

<GridLayout class="nt-form" rows="132,auto,auto,*">
    <Image height="128" src="res://logo"></Image>
    <Label row="1" class="page__content-placeholder" text="<!-- Page content goes here -->"></Label>
    <RadDataForm row="2" #myCommitDataForm [source]="person" tkExampleTitle tkToggleNavButton commitMode="Immediate" (propertyCommitted)="onPropertyCommitted($event)">
        <!-- >> angular-dataform-adjustment-html -->
        <TKEntityProperty tkDataFormProperty name="name" displayName="Name" index="0">
            <TKPropertyEditor tkEntityPropertyEditor type="Text">
                <TKPropertyEditorStyle tkPropertyEditorStyle strokeColor="#00695c" strokeWidth="2" fillColor="#4db6ac" labelHidden="false"
                labelTextSize="18" ios:labelFontName="Times New Roman" android:labelFontName="sans-serif-light" labelFontStyle="Italic"
                labelPosition="Top" labelTextColor="#00695c"></TKPropertyEditorStyle>
            </TKPropertyEditor>
            <TKNonEmptyValidator tkEntityPropertyValidators errorMessage="Username can't be empty."></TKNonEmptyValidator>
        </TKEntityProperty>
        <TKEntityProperty tkDataFormProperty name="age" displayName="Age" index="1">
            <TKPropertyEditor tkEntityPropertyEditor type="Number"></TKPropertyEditor>
        </TKEntityProperty>
        <TKEntityProperty tkDataFormProperty name="email" displayName="E-Mail" index="2">
            <TKPropertyEditor tkEntityPropertyEditor type="Email"></TKPropertyEditor>
        </TKEntityProperty>
        <TKEntityProperty tkDataFormProperty name="city" displayName="City" index="3" valuesProvider="Montreal, Quebec, Toronto" hintText="city">
            <TKPropertyEditor tkEntityPropertyEditor type="Picker"></TKPropertyEditor>
            <TKNonEmptyValidator tkEntityPropertyValidators errorMessage="City can't be empty."></TKNonEmptyValidator>
        </TKEntityProperty>
    </RadDataForm>
</GridLayout>
jmdavid commented 4 years ago

I haven't tested on iOS so far, I did and it works. So the bug is only in Android.

bundyo commented 4 years ago

Looks like just setting background-color or border to the text fields will reset all borders and the dropdown caret. Unfortunately removing those styles will break the dark mode styling, as the border and the dropdown caret remain black. So this looks more like a styling bug in RadDataForm.

As for the text field text styling - this is a bug/design decision in {N} - CSS styling has more priority than the properties of the control, so it won't be applied. You can override it with CSS with higher specificity. Something along those lines:

.ns-root PropertyEditor[type='Text'] DataFormEditorLabel {
    font-size: 18;
    font-style: italic;
    color: #00695c;
    position: top;
}

.ns-root PropertyEditor[type='Text'] DataFormEditorCore {
    border-color: #00695c; 
    border-width: 2;
    background-color: #4db6ac;
}
bundyo commented 4 years ago

For just Android, like this:

.ns-android PropertyEditor[type='Text'] DataFormEditorLabel {
    font-size: 18;
    font-style: italic;
    color: #00695c;
    position: top;
}
houssammehdi commented 4 years ago

All my RadDataForms started to look like this suddenly.

Is this the same problem?

https://github.com/NativeScript/NativeScript/issues/8607#issue-629523503

Is there a way to remove those styles being applied?

bundyo commented 4 years ago

Yes, looks like it.

houssammehdi commented 4 years ago

@bundyo is there a way to disable all this styling? I want my fields to have the default look on iOS. I've been looking everywhere with no hope, if I create a new project and add RadDataForm it doesn't look like the image shown at all. (My github issue ref)

bundyo commented 4 years ago

You can try if compat mode helps, but I guess not completely.

Maybe I can separate the {N}-UI components styling in a separate file that can be optionally not loaded. What do you think?

gustavotrott commented 1 year ago

For me it is caused by the @import '@nativescript/theme/css/core.css';.

specifically this style:

PickerField, DatePickerField, TimePickerField, DateTimePickerFields, DataFormEditorCore, RadAutoCompleteTextView {
  background-repeat: no-repeat;
  background-position: right center
}

But I'm not able to fix it... if I set any background* style to DataFormEditorCore, it stops showing the caret.