Package 

Class ViewModelInstance

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    
    public final class ViewModelInstance
     implements AutoCloseable
                        

    A view model instance for data binding which has properties that can be set and observed.

    The instance must be bound to a state machine for its values to take effect. This is done by passing it to Rive.

    • Method Detail

      • getNumberFlow

         final Flow<Float> getNumberFlow(String propertyPath)

        Creates or retrieves from cache a number property, represented as a cold Flow.

        The flow is subscribed to updates from the Rive worker while it is being collected.

        This flow emits every distinct value (up to the backing buffer limit). If you process the flow slowly, consider applying conflate if you only need the latest value to skip intermediate values. Alternatively, if you need to process every value, consider using a buffer operator with an appropriate buffer size to handle bursts.

        Collection of the flow may cause an exception:

        • RuntimeException: If this class has been closed, if the property does not exist on this view model instance, or is is of a different type.

        • IllegalStateException: If the backing Rive worker has been released.

        Parameters:
        propertyPath - The path to the property from this view model instance.
      • getStringFlow

         final Flow<String> getStringFlow(String propertyPath)

        Creates or retrieves from cache a string property, represented as a cold Flow.

        The collection of the flow may cause an exception. See getNumberFlow for details.

        Parameters:
        propertyPath - The path to the property from this view model instance.
      • getBooleanFlow

         final Flow<Boolean> getBooleanFlow(String propertyPath)

        Creates or retrieves from cache a boolean property, represented as a cold Flow.

        The collection of the flow may cause an exception. See getNumberFlow for details.

        Parameters:
        propertyPath - The path to the property from this view model instance.
      • getEnumFlow

         final Flow<String> getEnumFlow(String propertyPath)

        Creates or retrieves from cache an enum property, represented as a cold Flow. Enums are represented as strings, and this flow will emit the string value of the enum.

        The collection of the flow may cause an exception. See getNumberFlow for details.

        Parameters:
        propertyPath - The path to the property from this view model instance.
      • getColorFlow

         final Flow<Integer> getColorFlow(String propertyPath)

        Creates or retrieves from cache a color property, represented as a cold Flow. Colors are represented as AARRGGBB integers, and this flow will emit the integer value of the color.

        The collection of the flow may cause an exception. See getNumberFlow for details.

        Parameters:
        propertyPath - The path to the property from this view model instance.
      • getTriggerFlow

         final Flow<Unit> getTriggerFlow(String propertyPath)

        Creates or retrieves from cache a trigger property, represented as a cold Flow. Triggers emit Unit as the value, which simply indicates that the trigger has been fired.

        The collection of the flow may cause an exception. See getNumberFlow for details.

        Parameters:
        propertyPath - The path to the trigger property from this view model instance.
      • setNumber

         final Unit setNumber(String propertyPath, Float value)

        Sets a number property on this view model instance.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the property from this view model instance.
        value - The value to set the property to.
      • setString

         final Unit setString(String propertyPath, String value)

        Sets a string property on this view model instance.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the property from this view model instance.
        value - The value to set the property to.
      • setBoolean

         final Unit setBoolean(String propertyPath, Boolean value)

        Sets a boolean property on this view model instance.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the property from this view model instance.
        value - The value to set the property to.
      • setEnum

         final Unit setEnum(String propertyPath, String value)

        Sets an enum property on this view model instance. Enums are represented as strings.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the property from this view model instance.
        value - The string value of the enum to set the property to.
      • setColor

         final Unit setColor(String propertyPath, @ColorInt() Integer value)

        Sets a color property on this view model instance. Colors are represented as AARRGGBB integers.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the property from this view model instance.
        value - The integer value of the color to set the property to.
      • fireTrigger

         final Unit fireTrigger(String propertyPath)

        Fires a trigger on this view model instance.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the trigger property from this view model instance.
      • setImage

         final Unit setImage(String propertyPath, ImageAsset image)

        Assigns the given image to the image property on this view model instance.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the property from this view model instance.
        image - The image to assign to the property.
      • setArtboard

         final Unit setArtboard(String propertyPath, Artboard artboard)

        Assigns the given artboard to the bindable artboard property on this view model instance.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the property from this view model instance.
        artboard - The artboard to assign to the property.
      • insertToListAtIndex

         final Unit insertToListAtIndex(String propertyPath, Integer index, ViewModelInstance item)

        Inserts an item into a list property at the specified index.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Once the item is added to the list, you do not need to hold a reference to its instance. The list will also maintain a reference to the item.

        Parameters:
        propertyPath - The path to the list property from this view model instance.
        index - The index at which to insert the item.
        item - The view model instance to insert into the list.
      • appendToList

         final Unit appendToList(String propertyPath, ViewModelInstance item)

        Appends an item to the end of a list property.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Once the item is added to the list, you do not need to hold a reference to its instance. The list will also maintain a reference to the item.

        Parameters:
        propertyPath - The path to the list property from this view model instance.
        item - The view model instance to append to the list.
      • removeFromListAtIndex

         final Unit removeFromListAtIndex(String propertyPath, Integer index)

        Removes an item from a list property at the specified index.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the list property from this view model instance.
        index - The index of the item to remove.
      • removeFromList

         final Unit removeFromList(String propertyPath, ViewModelInstance item)

        Removes an item from a list property.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the list property from this view model instance.
        item - The view model instance to remove from the list.
      • swapListItems

         final Unit swapListItems(String propertyPath, Integer indexA, Integer indexB)

        Swaps two items in a list property by their indices.

        ℹ️ Changes to bound Rive elements will not be reflected until the next state machine advance.

        Parameters:
        propertyPath - The path to the list property from this view model instance.
        indexA - The index of the first item to swap.
        indexB - The index of the second item to swap.