Skip to content

Add example CustomAgentforceView and wire ViewProvider in HomeScreen#35

Open
asikora-sf wants to merge 13 commits intosalesforce:devfrom
asikora-sf:stack/viewprovider/06-example-usage
Open

Add example CustomAgentforceView and wire ViewProvider in HomeScreen#35
asikora-sf wants to merge 13 commits intosalesforce:devfrom
asikora-sf:stack/viewprovider/06-example-usage

Conversation

@asikora-sf
Copy link
Contributor

Summary

  • Creates CustomAgentforceView React Native component that renders in place of native SDK views
  • Registers it via AppRegistry.registerComponent() in index.js
  • HomeScreen checks enableCustomViewProvider feature flag on mount
  • When enabled, registers the delegate for copilot/richText and copilot/markdown types
  • Cleans up on unmount via clearViewProviderDelegate()

Stack

PR 6/6 (final) in the viewprovider stack. Depends on PRs #30-#34.

Test plan

  • With "Custom View Provider" flag OFF: conversation renders native SDK views (no change)
  • With flag ON: copilot/richText and copilot/markdown components render as React Native views with blue "Custom RN View" badge
  • Custom view receives definition and properties props from native
  • Toggling the flag and relaunching conversation switches between native and custom views

How to test end-to-end

  1. Launch the app
  2. Go to Settings > Flags > enable "Custom View Provider"
  3. Configure and launch a conversation
  4. Agent responses containing rich text or markdown should render with the blue "Custom RN View" badge

Replace componentTypes[] + reactComponentName with a componentMap
Record<string, string> so each SDK component type maps to its own
React Native component name.
Bridges the native SDK view customization to React Native via RCTRootView.
- BridgeViewProvider: canHandle() checks pre-registered types, view() renders RCTRootView in SwiftUI
- registerViewProvider/clearViewProvider native methods exposed to JS
- ViewProvider passed to AgentforceClient init when registered
Replace Set<String> + single reactComponentName with a [String: String]
dictionary mapping each component definition to its own React component.
canHandle() checks map keys, view() looks up the component name per type.
@asikora-sf asikora-sf force-pushed the stack/viewprovider/06-example-usage branch from e2763f4 to b89f3e3 Compare March 5, 2026 22:31
RCTRootView embedded in UIViewRepresentable was getting zero size
because SwiftUI had no sizing information. Set sizeFlexibility and
implement sizeThatFits so the React content measures correctly.
Bridges the native SDK view customization to React Native via ReactRootView.
- BridgeViewProvider: canHandle() checks pre-registered types, GetView() renders ReactRootView in Compose
- registerViewProvider/clearViewProvider React methods exposed to JS
- ViewProvider passed to AgentforceConfiguration builder when registered
Change BridgeViewProvider from N:1 (multiple types → one component) to
1:1 mapping (each type → its own React component name). The register()
method now accepts a Map<String, String> and GetView() looks up the
per-type component name from the map.

Also update registerViewProvider in AgentforceModule to read componentMap
from the ReadableMap instead of componentTypes array + reactComponentName.
…ceService

Exposes view provider registration to JS consumers:
- setViewProviderDelegate() registers component types + React component name with native
- clearViewProviderDelegate() removes registration
- Cleanup in destroy()
Pass componentMap (Record<string, string>) to native registerViewProvider
instead of componentTypes array + reactComponentName, matching the 1:1
design change in the native layers.
…istence

- Adds Custom View Provider toggle to Feature Flags tab in Settings
- Persists flag via UserDefaults (iOS) and SharedPreferences (Android)
- Reads/writes in getFeatureFlags, setFeatureFlags, and configure paths
- CustomAgentforceView: React Native component that renders in place of native SDK views
- Registered via AppRegistry in index.js for native RCTRootView/ReactRootView rendering
- HomeScreen checks enableCustomViewProvider flag and registers the delegate on mount
- Handles copilot/richText and copilot/markdown as an example
Use the new 1:1 componentMap format in registerViewProviderIfEnabled
instead of the old componentTypes + reactComponentName.
Replace raw JSON dump with recursive ValueRenderer that breaks out
nested objects and arrays into structured tables up to 6 levels deep.
Deeper nesting progressively compacts padding and key widths to stay
usable on mobile screens.
@asikora-sf asikora-sf force-pushed the stack/viewprovider/06-example-usage branch from be185e9 to 667a4dc Compare March 5, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants