Code Monkey home page Code Monkey logo

Comments (4)

ellykits avatar ellykits commented on May 25, 2024

Hi @jdesbonnet. Thank you for your feedback. There are two approaches to this: 1 is to create a text_color attribute on the DatePicker widget and possibly do the same for the other widgets as well. 2. add an attribute for styling individual widget globally. This attribute would work like Android style. I have created an issue for tracking this here Styling Widgets I would prefer second approach because of the flexibility it offers.

from neat-form.

ellykits avatar ellykits commented on May 25, 2024

Hi @jdesbonnet. I have started working on this issue as mentioned in my previous comment. I will be creating a pull request with this fix soon. Here is how it will work.

NOTE: This fix will be available for all the widgets and can be used to override any of the default styles.

Step 1: Declare Style
E.g.

  <style name="sampleDatePickerStyle" parent="Widget.AppCompat.EditText">
    <item name="android:textSize">18sp</item>
    <item name="android:textColor">#4D9D4B</item>
  </style> 

Step 2: Supply the style to the form builder
Before creating the form supply the style to the FormBuilder. I have introduced a resourcesMap that can be accessed via the FormBuilder. Which is a map of resource name (as defined in the widget's JSON) against the actual Android resource style. E.g. stylesMap["sampleDatePickerStyle"] = R.style.sampleDatePickerStyle

    formBuilder.populateResourceMap(R.drawable::class.java)
    formBuilder.populateResourceMap(R.style::class.java)

NOTE: we are explicitly calling the populate methods with the resources class in order to get the correct class name for the resources. We can't do this within the library because there R.drawable would only pick drawables available in the library alone but not for the app.

Step 3: Apply the style to the widget
Example:

    {
          "name": "dob",
          "type": "datetime_picker",
          "properties": {
            "hint": "Enter birth date",
            "type": "date_picker",
            "display_format": "dd/MM/yyyy",
            "min_date": "today-80y",
            "max_date": "today",
            "style": "sampleDatePickerStyle"
          }
     }

NOTE: Just make sure the name of the style in the widget's JSON matches the name in stylesMap

from neat-form.

ellykits avatar ellykits commented on May 25, 2024

@jdesbonnet I updated the comment above. I made some slight adjustments. Instead of manually adding individual styles to the resourceMap, I added a utility method to assist with this (populateResourceMap). This will use reflection to fetch all the drawables and styles available in the app. For now it has to be called explicitly before building the form. Afterwards you can apply styling to widget's as supported. I also added background attribute for widget type edit_text that works in a similar way.

from neat-form.

ellykits avatar ellykits commented on May 25, 2024

Closed this. Issue fixed in v1.1.3

from neat-form.

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.