How to Add and Use Remote Feature Flags in a Plugin
Overview
Feature flags allow you to enable or disable specific functionality dynamically, making it easier to roll out new features. From now on, feature flags will not be provided in the common scope. Instead, feature flags should be defined within the plugin itself. This document outlines the steps developers need to follow to add and use remote feature flags in a plugin.
Steps to Follow
1. Define the Feature Flag Name
- The feature flag name should be common for both platforms (iOS and Android).
- If the feature flag is specific to one platform, specify this in the CMS configuration.
- Define the minimum application version and other CMS-required details in the CMS configuration or communicate with the CMS team.
- For more details, refer to the relevant document [link].
2. Add the Feature Flag Key in the Plugin
- On the application side, if you are adding a flag for a particular plugin:
- Create a constant inside the specific plugin.
- We can common constants for a specific plugin
Example:
object ScalableNavigationFlags {
const val FF_HOMEPAGE_UPDATED_GOAL_STATUS_DIALOG = "HomePageUpdatedGoalStatusDialog"
const val FF_HOMESCREEN_PERSONALIZED_CONTENT = "HomeScreenPersonalizedContent"
}
3. Retrieve the Feature Flag Value in the ViewModel
- If you need to check the feature flag logic, retrieve the feature flag value in the ViewModel.
- Use the
ocFeatureFlagManager
to retrieve the value of the feature flag.
Example:
ocFeatureFlagManager.getValue(FF_HOMESCREEN_PERSONALIZED_CONTENT)
- If additional logic is required, ensure it is implemented in the ViewModel to keep the code modular and maintainable.
4. Use the Feature Flag in Your Plugin
- Once the feature flag value is fetched, use it to toggle functionality in your plugin.
- Ensure that the feature flag logic is implemented in a way that does not affect the performance of the application.
Example:
if isEnabled {
// Enable the feature
} else {
// Disable the feature
}
Best Practices
- Use Descriptive Names: Ensure feature flag names are meaningful and easy to understand.
- Keep Flags Short-Lived: Remove unused feature flags to avoid clutter.
- Test Thoroughly: Test feature flags in both enabled and disabled states.
- Coordinate with CMS Team: Ensure proper configuration and documentation in the CMS.
Example Workflow
-
Define the Feature Flag in CMS:
- Add the feature flag name, description, and minimum application version in the CMS.
- Share the feature flag key with the development team.
-
Add the Feature Flag Key in the Plugin:
- Create or update the FeatureFlag Constants in the plugin's Constants file.
-
Retrieve the Feature Flag Value:
- Use the
OCFeatureFlagManager
to retrieve the value of the feature flag in the ViewModel.
- Use the
-
Implement the Feature Flag Logic:
- Use the fetched value to toggle functionality in the plugin.
Conclusion
By following these steps, you can effectively add and manage remote feature flags within your plugin. This approach ensures better modularity, maintainability, and flexibility in your application, allowing you to roll out features safely and dynamically.