Utility Commands

AddEventToCalendar

You finally did it. You built that (almost) perfect calendar event detail page. It looks pretty, it shows all the information. You even got the time zone right! If only you could have that "Add to Calendar" button like everybody else.

Well, now your calendar event detail page can be perfect. This command allows you to specify all the details of a one-time event and add it to the user's default calendar.

The first time this command (or any other that accesses the calendar) is used it will prompt the user to allow access to their calendars.

The following properties are required at a bare minimum:

  • StartDateTime

  • Title

  • TimeZoneId

<Button Text="Add to Calendar" Command="{Binding AddEventToCalendar}">
    <Button.CommandParameter>
        <Rock:AddEventToCalendarParameters Title="Rock Solid Finances Class"
            StartDateTime="2021-07-04 18:30:00"
            EndDateTime="2021-07-04 20:00:00"
            Location="3120 W Cholla St, Phoenix AZ, 85029-4113"
            Url="https://www.rocksolidchurchdemo.com/page/414?EventOccurrenceId=3"
            TimeZoneId="America/Phoenix" />
    </Button.CommandParameter>
</Button>

AggregateCommand

This is a special-use command. It allows you to chain multiple commands together. A common usage of this would be to combine the SetContext and ReplacePage commands to change an Entity context and then reload the current page.

You specify the child commands to execute by using an instance of the AggregateCommandParameters object.

<Button Text="Tap"
    Command="{Binding AggregateCommand}">
    <Button.CommandParameter>
        <Rock:AggregateCommandParameters>
            <Rock:CommandReference Command="{Binding SetContext}">
                <Rock:CommandReference.CommandParameter>
                    <Rock:SetContextParameters Name="Campus"
                        Value="0a3a20eb-c4a8-44fe-9daf-d22b88fae377" />
                </Rock:CommandReference.CommandParameter>
            </Rock:CommandReference>
            <Rock:CommandReference Command="{Binding ReplacePage}"
                CommandParameter="b06173ed-aa2f-43d8-bd38-eb5becca1cbe" />
        </Rock:AggregateCommandParameters>
    </Button.CommandParameter>
</Button>

Callback

Some blocks, currently just the Content block, support what is called Callbacks. You can learn more about these in the Advanced: Dynamic Content and the Developer chapters. But, for our purposes here, you can think of these as an API call back to the server's logic for the block.

If the CommandParameter is a plain string, then it is used as the name of the callback function to be queried on the server. If you need to pass any parameters to that function then CommandParameter should point to an instance of the CallbackParameters object.

Examples

<Button Text="Tap"
    Command="{Binding Callback}"
    CommandParameter="UserTap" />
<Button Text="Tap"
    Command="{Binding Callback}">
    <Button.CommandParameter>
        <Rock:CallbackParameters>
            <Rock:Parameter Name="GroupId" Value="18" />
        </Rock:CallbackParameters>
    </Button.CommandParameter>
</Button>

DownloadPass

This command can be used to download a pass directly to Apple Wallet (with user permission). This can be used to provide a nicer experience of adding a pass to the wallet without having to go through a browser intermediary.

You may want to consider hiding a button with this command on Android since the functionality is mainly intended for iOS. On Android, this command will simply open an external browser with the URL matching the command parameter. To learn how to show/hide an element based on the device platform, take a look at our On Device Platform markup extension.

Examples

<Button Text="Download Pass"
    Command="{Binding DownloadPass}"
    CommandParameter="https://church.com/pass.pkpass" />

EnablePushNotifications

Normally, notifications are enabled by the application automatically on launch or during the onboarding process of a new user. But sometimes you might want to display a custom page that talks about why you are going to be sending them push notifications to encourage a better response. This command allows you to initiate the request to enable push notifications.

You might want to check out the Push Notification State section for an example of how to integrate this command with UI that updates automatically based on notifications being enabled or disabled.

The optional CommandParameter is an instance of the EnablePushNotificationsParameters object that is outlined below.

Be aware that Android does not ever show a popup message. Instead, it will just automatically enable notifications and then show your EnabledMessage.

Logout

This command will allow you to logout the current person from the application. It will then redirect to the homepage.

  • A string that contains either the value "True" to indicate that the current page should be reloaded, or the Guid of the page to show instead of the home page.

  • An instance of the LogoutParameters object that is outlined below.

<Button Text="Logout" 
    Command="{Binding Logout}" />

PrayForRequest

Prayer is a big thing for churches, at least it should be. To that end, we wanted to make prayer in your mobile applications as easy as possible. Rather than being limited to specific blocks that support prayer, we decided to give you a command that is available in any block. Using this command you can easily add "Pray" buttons to any page and any content block.

The CommandParameter can either be a plain string that represents the unique identifier (Guid) of the prayer request, or it can be an instance of the PrayForRequestParameters object.

Examples

The first example is a simple Pray button. No special processing happens, it just increments the prayer count for the request.

<Button Text="Pray"
    StyleClass="btn,btn-primary"
    Command="{Binding PrayForRequest}"
    CommandParameter="40C6134E-994B-4B11-9711-E867D894FE1B" />

This second example makes use of the PrayForRequestParameters object to disable the interaction and also provide a workflow to be launched.

<Button Text="Pray"
    StyleClass="btn,btn-primary"
    Command="{Binding PrayForRequest}">
    <Button.CommandParameter>
        <Rock:PrayForRequestParameters Guid="40C6134E-994B-4B11-9711-E867D894FE1B"
            RecordInteraction="False"
            WorkflowTypeGuid="27B5E487-D451-4025-8BEB-C4EDC354617C" />
    </Button.CommandParameter>
</Button>

PageEvent

You learned, or will learn, elsewhere that you can use Lava on the mobile shell to handle certain page events and respond to them. Normally these page events are just ones generated by the system for you. However, you can trigger your own custom page events using this command.

The CommandParameter can either be a plain string that indicates the event name to be triggered, or it can be an instance of the PageEventParameters object. This latter method allows you to pass parameters into your lava logic.

Examples

<Button Text="Tap"
        Command="{Binding PageEvent}"
        CommandParameter="UserTap" />
<Button Text="Tap"
        Command="{Binding PageEvent}">
    <Button.CommandParameter>
        <Rock:PageEventParameters Event="UserTap">
            <Rock:Parameter Name="GroupId" Value="18" />
        </Rock:PageEventParameters>
    </Button.CommandParameter>
</Button>

PerformHapticFeedback

This is to perform Haptic Feedback on a user's device. If you are unfamiliar with what haptic feedback is, here is a good reference.

The CommandParameter is a string, but can be left out unless you specifically want to implement the "LongPress" type. Everything else will default to the "Click" type.

Examples

// Example with no command parameter. Defaults to "Click".
<Button Text="Haptic"
    Command="{Binding PerformHapticFeedback}" />
// Example with the "LongPress" command parameter.
<Button Text="Haptic LongPress"
    Command="{Binding PerformHapticFeedback}" CommandParameter="LongPress" />

ReloadApplication

This instructs the application to reload as if you had just forced quit and started it again. This is a development tool that saves a few seconds when debugging stuff. It's not a command you'll want to use in a public app.

The CommandParameter is not used and will be ignored.

<Button Text="Reload"
    Command="{Binding ReloadApplication}" />

ReloadPage

This instructs the application to reload the currently displayed page.

The CommandParameter is not used and will be ignored.

<Button Text="Reload"
    Command="{Binding ReloadPage}" />

ScrollToVisible

There are two ways to initiate this command, we'll show them below. But the basic syntax is you specify the Anchor element that should be scrolled until it becomes visible. Think of this like the HTML Anchor href, or a "jump to" button.

You can either pass the view to be made visible directly by reference in the CommandParameter or you can pass an instance of the ScrollToVisibleParameters object.

The options you have with the Position parameter are as follows:

  • MakeVisible - Just make sure the anchor is visible on screen

  • Start - Attempt to scroll until the anchor is at the start (top or left) of the screen

  • Center - Attempt to scroll until the anchor is at the center of the screen

  • End - Attempt to scroll until the anchor is at the end (bottom or right) of the screen

Examples

<StackLayout>
    <Button Text="Scroll"
        Command="{Binding ScrollToVisible}"
        CommandParameter="{x:Reference myLabel}" />

    <BoxView Color="Red"
        HeightRequest="1200" />

    <Label Text="My Label"
        x:Name="myLabel" />

    <BoxView Color="Blue"
        HeightRequest="1200" />
</StackLayout>

The above will scroll the first ScrollView in the view tree above the Label we specified as our anchor so that the label is visible. This by itself may be just fine for what you need, but it may not end up doing what you want. By default, the anchor will be scrolled until it becomes "just visible". In this case, since we need to scroll down, the label will end up at the bottom of the screen.

To accommodate those situations, you can specify a parameters object like so.

<Button Text="Scroll"
    Command="{Binding ScrollToVisible}">
    <Button.CommandParameter>
        <Rock:ScrollToVisibleParameters Anchor="{x:Reference myLabel}"
            Position="Start" />
    </Button.CommandParameter>
</Button>

This still indicates the same Label we want to use as the Anchor, but it also specifies the position we want it to end up at. Now, this is not a forced position. If there were nothing below the label, it wouldn't be possible for it to end up at the top. But since we have a lot of content below as well, there is enough room to scroll.

Finally, due to the way XAML works, there is a shorthand to the XAML above.

<Button Text="Scroll"
    Command="{Binding ScrollToVisible}"
    CommandParameter="{Rock:ScrollToVisibleParameters Anchor={x:Reference myLabel}, Position=Start}" />

SetAppValue

<Button Text="Remove Value"
    Command="{Binding SetAppValue}"
    CommandParameter="KeyToRemove" />
<Button Text="Set Value"
    Command="{Binding SetAppValue}"
    CommandParameter="KeyToSet=SomeValue" />

To utilize an app value, you have access to an AppValues dictionary in Lava:

{{ AppValues | ToJSON }}

SetContext

This command allows you to set an entity context value based on a user's action. For example, you could build a custom Campus Context Picker and set the context when the user taps an action button.

The parameter should be an instance of the SetContextParameters class, which is described below.

<Button Text="Tap"
    Command="{Binding SetContext}">
    <Button.CommandParameter>
        <Rock:SetContextParameters Name="Campus"
           Value="e4d80e57-da60-4822-bc22-c071f02958e8" />
    </Button.CommandParameter>
</Button>

SetUserPreference

Save user-specific properties that we only store on the shell. Be careful not to go overboard with these, as they directly affect your application size. In reality, this is just a SetAppValue command that prefixes the key with user-preference-.

<Button Text="Set User Preference"
    Command="{Binding SetUserPreference}"
    CommandParameter="KeyToSet=SomeValue" />
<Button Text="Remove User Preference"
    Command="{Binding SetUserPreference}"
    CommandParameter="KeyToRemove" />

SetViewProperty

There may be times you want to modify the appearance of something or hide it completely, in response to a user action. This command will let you change a property value on a view in your XAML. Here are a few quick examples:

  • Change the StyleClass values applied to a view

  • Show or hide a view by changing IsVisible

  • Disable another button

You might be tempted to try disabling the button that the command is attached to. This will most likely not work. When the command finishes executing the button will be automatically re-enabled. In these cases, you might need to hide the button and show a different, already disabled, button instead.

The CommandParameter must specify an instance of the SetViewPropertyParameters object.

You may notice above that there are two ways to set a property value. If you are only setting a single value you will probably find the Name and Value properties easier to deal with. But you can also set multiple properties at one time by using the Values collection instead. You cannot set properties on multiple views; for that, you would need to use multiple SetViewProperty commands.

Examples

This first example demonstrates a simple action. When the button is tapped then the style class will change from success to danger.

<Button x:Name="myButton"
    StyleClass="btn,btn-success"
    Text="Tap Me"
    Command="{Binding SetViewProperty}"
    CommandParameter="{Rock:SetViewPropertyParameters View={x:Reference myButton}, Name=StyleClass, Value='btn,btn-danger'}" />

Our next example will show a more advanced version that changes two properties. We are going to do the same transition to a danger button, but also change the text displayed in the button. The first example showed the concise form, but it's a bit harder to read because of how long that string is. The second example will also show the more verbose form, which is a bit easier to read.

<Button x:Name="myButton2"
    StyleClass="btn,btn-success"
    Text="Tap Me"
    Command="{Binding SetViewProperty}">
    <Button.CommandParameter>
        <Rock:SetViewPropertyParameters View="{x:Reference myButton2}">
            <Rock:Parameter Name="StyleClass" Value="btn,btn-danger" />
            <Rock:Parameter Name="Text" Value="Tapped" />
        </Rock:SetViewPropertyParameters>
    </Button.CommandParameter>
</Button>

Our final example shows how to modify two views in response to a single action using the AggregateCommand. In this case, we want to disable the button after it is tapped. But since we can't directly modify the IsEnabled property (since it gets re-enabled after the command finishes) we have to swap it out with a different button. Instead, we first make "myButton3" visible and then make "myButton4" invisible.

<Button x:Name="myButton3"
    StyleClass="btn,btn-success"
    Text="Tap Me"
    IsEnabled="False"
    IsVisible="False" />
<Button x:Name="myButton4"
    StyleClass="btn,btn-success"
    Text="Tap Me"
    Command="{Binding AggregateCommand}">
    <Button.CommandParameter>
        <Rock:AggregateCommandParameters>
            <Rock:CommandReference Command="{Binding SetViewProperty}">
                <Rock:SetViewPropertyParameters View="{x:Reference myButton3}"
                    Name="IsVisible"
                    Value="True" />
            </Rock:CommandReference>
            <Rock:CommandReference Command="{Binding SetViewProperty}">
                <Rock:SetViewPropertyParameters View="{x:Reference myButton4}"
                    Name="IsVisible"
                    Value="False" />
            </Rock:CommandReference>
        </Rock:AggregateCommandParameters>
    </Button.CommandParameter>
</Button>

ShowActionPanel

This action will show an action panel (think action sheet in iOS terms). This is basically a popup that contains a short message and a number of buttons the user can choose from. A common example of this would be a "reply" button in a mail application. When tapping the button it might then pop up an action sheet that contains a few buttons to help you decide what you intend to do: Reply, Reply All, Forward.

These popups usually have a Cancel button (though it's not strictly required). Additionally, you can specify a single "destructive" button that stands out to the user. Often, this would be a Delete type action and is usually styled red.

The CommandParameter must specify an instance of the ShowActionPanelParameters object.

Examples

<Button Text="Actions"
    StyleClass="btn, btn-primary"
    Command="{Binding ShowActionPanel}">
    <Button.CommandParameter>
        <Rock:ShowActionPanelParameters Title="My Action Sheet"
            CancelTitle="Do Nothing">
            <Rock:ShowActionPanelParameters.DestructiveButton>
                <Rock:ActionPanelButton Title="Delete"
                    Command="{Binding PushPage}"
                    CommandParameter="c258265c-9645-46f1-a69b-0e0f149e5e83" />
            </Rock:ShowActionPanelParameters.DestructiveButton>
            <Rock:ActionPanelButton Title="First Button"
                Command="{Binding OpenBrowser}"
                CommandParameter="https://www.rockrms.com" />
            <Rock:ActionPanelButton Title="Second Button"
                Command="{Binding OpenExternalBrowser}"
                CommandParameter="https://community.rockrms.com/" />
        </Rock:ShowActionPanelParameters>
    </Button.CommandParameter>
</Button>

Thanks to the magic of XAML, we can simplify the definition of the destructive button a bit if we want, it's up to you.

<Button Text="Actions"
    StyleClass="btn, btn-primary"
    Command="{Binding ShowActionPanel}">
    <Button.CommandParameter>
        <Rock:ShowActionPanelParameters Title="My Action Sheet"
            CancelTitle="Do Nothing"
            DestructiveButton="{Rock:ActionPanelButton Title=Delete, Command={Binding PushPage}, CommandParameter=c258265c-9645-46f1-a69b-0e0f149e5e83}">
            <Rock:ActionPanelButton Title="First Button"
                Command="{Binding OpenBrowser}"
                CommandParameter="https://www.rockrms.com" />
            <Rock:ActionPanelButton Title="Second Button"
                Command="{Binding OpenExternalBrowser}"
                CommandParameter="https://community.rockrms.com/" />
        </Rock:ShowActionPanelParameters>
    </Button.CommandParameter>
</Button>

Write Interaction

Allows you to write an Interaction to Rock when the command is executed. For example, you could write an interaction in response to the user tapping a button. By default, only a single Interaction will be written no matter how many times the command is executed. Normally this is probably what you want. If for some reason you want to allow multiple Interactions to be generated, set the IsMultipleAllowed property to true.

This command takes a parameter object of type InteractionParameters that contains the following details.

Parameters

In order for your parameters to be considered valid, you must provide at least one of ChannelId or ChannelGuid; and you must provide at least one of ComponentId or ComponentName. Also, note that some event sources will provide defaults for some of the properties in the table below or may even override a value you provide.

Example

<Button Text="Like" Command="{Binding WriteInteraction}">
    <Button.CommandParameter>
        <Rock:InteractionParameters Operation="Like"
            Summary="I like this."
            ChannelId="3"
            ComponentId="87" />
    </Button.CommandParameter>
</Button>

ShowPopup

Rock Mobile Shell supports the idea of small popup pages. These don't support navigation but can be useful for a simple display of additional content without leaving the current page.

If the CommandParameter is a string then it will be interpreted as a page GUID with optional query string parameters. This will display a full Rock page inside the popup view.

Alternatively, you can specify a view to use as the content for the popup. This is ideal for showing additional details of items or perhaps a list filter.

Finally, you can specify a ShowPopupParameters object and supply additional options as seen below.

Examples

<Button Text="Tap"
    Command="{Binding ShowPopup}"
    CommandParameter="e4d80e57-da60-4822-bc22-c071f02958e8?GroupId=18&amp;Mode=Edit" />
<Button Text="Tap"
    Command="{Binding ShowPopup}">
    <Button.CommandParameter>
        <Rock:ShowPopupParameters Title="Select Group"
            PageGuid="e4d80e57-da60-4822-bc22-c071f02958e8">
            <Rock:Parameter Name="ParentGroupId" Value="8293" />
        </Rock:ShowPopupParameters>
    </Button.CommandParameter>
</Button>
<Button Text="Tap"
    Command="{Binding ShowPopup}">
    <Button.CommandParameter>
        <Rock:ShowPopupParameters Title="Select Group"
            Anchor="Top">
            <Rock:ShowPopupParameters.Content>
                <StackLayout>
                    <Label Text="Hello Rock" />
                    <Button Text="Close"
                        Command="{Binding ClosePopup}" />
                </StackLayout>
            </Rock:ShowPopupParameters.Content>
        </Rock:ShowPopupParameters>
    </Button.CommandParameter>
</Button>

ClosePopup

This command is the opposite of the ShowPopup command. If there is an open popup then it will be closed. This command takes no parameters.

<Button Text="Close"
    Command="{Binding ClosePopup}" />

Follow

The command is used to follow and unfollow specific entities.

Previously, this behavior was only utilized using the Following Icon, but now with this command, you can easily mimic that to create custom follow/unfollow buttons.

When following a person you'll want to use the PersonAlias entity type, not the Person.

Note that this command does not refresh the page. If you have following icons and expect them to be updated from this command, it does not work as such. Consider using SetViewProperty to make visual changes in response to follow and unfollow actions.

Examples

<StackLayout Orientation="Horizontal">
    {% assign group = 70 | GroupById %}
    
    <Button Text="Follow"
        Command="{Binding Follow}">
        <Button.CommandParameter>
            <Rock:FollowParameters EntityId="{{ group.Id }}"
                EntityTypeId="{{ group.TypeId }}" />
        </Button.CommandParameter>
    </Button>
    
    <Button Text="Unfollow"
        Command="{Binding Follow}">
        <Button.CommandParameter>
            <Rock:FollowParameters IsFollow="False"
                EntityId="{{ group.Id }}"
                EntityTypeId="{{ group.TypeId }}"
                NotificationText="Unfollowed!" />
        </Button.CommandParameter>
    </Button>
</StackLayout>

ShowToast

This command displays a "Toast" style message, often used to show quick and temporary messages, such as "saved" or "updated" and things of the sort.

If the CommandParameteris a string, it will display using the default styles with the command parameter as the message to display.

Examples

<Button Text="Toast Me"
    Command="{Binding ShowToast}"
    CommandParameter="Default Toast styling." /> 
<Button Text="Toast Me 2"
    Command="{Binding ShowToast}"
    CommandParameter="{Rock:ShowToastParameters Text='Butter or jam?' Duration='Long' FontSize='32'}" />

ShowCoverSheet

Shows a Cover Sheet.

<Button Text="Tap"
    StyleClass="btn, btn-primary"
    Command="{Binding ShowCoverSheet}"
    CommandParameter="71e80253-8d10-426b-8182-65dafe9b695f" /> <!-- Page Guid -->

CloseCoverSheet

Closes any open Cover Sheet.

<Button Text="Tap"
    Command="{Binding CloseCoverSheet}" />

UpdatePersonProfilePhoto

This command is used to update the profile photo of either the CurrentPerson, or if a PersonGuid is supplied as the parameter, it will update theirs. Options are shown with the ShowActionPanel command, including uploading an existing photo or capturing a new one.

This command requires Edit permissions on the following API endpoint: POST api/People/UpdatePersonProfilePhoto?personGuid={personGuid}&filename={filename}

<Button Text="Update Photo"
    Command="{Binding UpdatePersonProfilePhoto}"
    CommandParameter="8fedc6ee-8630-41ed-9fc5-c7157fd1eaa4" />

There are some additional command parameters that can be used for extended functionality. These are UpdatePersonProfilePhotoCommandParameters.

Here's an example for using the Image property:

<Rock:Image x:Name="PersonImage"
    Source="image.png" />

<Button Text="Update Photo"
    Command="{Binding UpdatePersonProfilePhoto}">
    <Button.CommandParameter>
        <Rock:UpdatePersonProfilePhotoCommandParameters Image="{x:Reference Name=PersonImage}" />
    </Button.CommandParameter>
</Button>

CreateEntitySetAndNavigate

This command is pretty complex. It does two things... First it generates an Entity Set based on the provided parameters and then performs a Navigation command with an appended query string of the entity set value.

<Button Text="Create Entity Set And Navigate"
    Command="{Binding CreateEntitySetAndNavigate}">
    <Button.CommandParameter>
        <Rock:CreateEntitySetAndNavigateParameters EntityTypeGuid="72657ED8-D16E-492E-AC12-144C5E7567E7">
            <Rock:CreateEntitySetAndNavigateParameters.EntityItemGuids>
                <x:String>66D0FD8B-BFA0-41EA-8DAD-000040D0890D</x:String>
                <x:String>EE161CC8-5C25-4BA2-9E41-0000C8B80A39</x:String>
            </Rock:CreateEntitySetAndNavigateParameters.EntityItemGuids>
            <Rock:CreateEntitySetAndNavigateParameters.NavigateCommand>
                <Rock:CommandReference Command="{Binding PushPage}"
                    CommandParameter="f0ef45ac-4eb8-4ad1-b817-408d7d7fe0fc" />
            </Rock:CreateEntitySetAndNavigateParameters.NavigateCommand>
        </Rock:CreateEntitySetAndNavigateParameters>
    </Button.CommandParameter>
</Button>

Last updated

⚙️ Powered by Rock RMS