Overview
Code Screens act as placeholders in your Muta flows that are replaced with native SwiftUI views at runtime. This enables you to:- Add authentication screens to your onboarding flows
- Integrate payment processing directly in your flows
- Include complex native UI that requires custom logic
- Maintain remote configurability while using native code
How It Works
1
Create a Code Screen
In the Muta web editor, add a “Code Screen” to your flow and give it a unique name (e.g., “Login Screen”, “Payment Form”)
2
Configure Navigation
Set up the continue and back navigation destinations for your code screen
3
Inject Components
Pass your SwiftUI views when displaying the placement in your app
Implementation
Basic Setup
Pass your custom views when callingdisplayPlacement:
Component Interface
Your injected views receive aCodeScreenContext with the following properties:
Example Component
Here’s a complete example of a login screen component:Animations
Code screens automatically animate in and out matching your flow’s configured animations:- Entry Animation: Matches the animation used when navigating TO the code screen
- Exit Animation: Uses the configured continue/back animation settings
- Seamless Transitions: Native screens blend smoothly with your flow screens
Use Cases
Authentication Flows
Integrate login, signup, or authentication screens directly into your onboarding:Payment Integration
Add payment processing without breaking the flow experience:Complex Forms
Handle multi-step forms or complex data entry:Best Practices
Screen Naming
Screen Naming
- Use descriptive, unique names for your code screens
- Keep names consistent between the Muta editor and your code
- Avoid special characters in screen names
Error Handling
Error Handling
- Always handle errors gracefully in your views
- Provide clear feedback to users
- Consider offering retry options for network failures
Performance
Performance
- Keep views lightweight and focused
- Avoid heavy computations in body methods
- Use
@Stateand@Bindingappropriately
Events
When code screens are displayed or interacted with, the SDK emits specific events:Troubleshooting
Common Issues
Code screen not appearing:- Verify the screen name matches exactly (case-sensitive)
- Ensure the view is properly wrapped in
AnyView - Check that injectedScreens is passed to displayPlacement
- Confirm you’re calling
onContinue()oronBack() - Check that navigation destinations are configured in the editor
- Ensure no SwiftUI errors are preventing execution
- Verify presentationType is set appropriately
- Check that animation durations are reasonable (200-500ms)
- Ensure views render quickly to avoid animation lag