The MagicFeedback Popup SDK includes built-in support for React Native through a specialized renderer that adapts to the React Native environment. The SDK automatically detects React Native and uses the appropriate renderer.
The ReactNativePopupRenderer is a specialized implementation designed for React Native apps. It provides a bridge between the SDK and your React Native UI layer.
src/platform/react-native-renderer.ts
export class ReactNativePopupRenderer implements PopupRenderer { private mounted = false; private lastSurveyId: string | null = null; private emitFn: ((type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void) | null = null; private onCloseFn: (() => void) | null = null; private completed = false; init(): void { // Prepare any state / native module listeners // This is where you could initialize a NativeModule or global store } show( surveyId: string, productId: string, data: Record<string, unknown> | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void ): void { this.mounted = true; this.lastSurveyId = surveyId; this.emitFn = emit; this.onCloseFn = onClose; this.completed = false; // Emit popup shown event queueMicrotask(() => emit('popup_clicked', surveyId, data)); console.log('[ReactNativePopupRenderer] show survey:', { surveyId, productId, data }); } /** Complete the survey from the native layer */ public completeSurvey(data?: Record<string, unknown>): void { if (!this.mounted || this.completed || !this.lastSurveyId || !this.emitFn) return; this.completed = true; this.emitFn('survey_completed', this.lastSurveyId, data); // Close popup this.onCloseFn?.(); this.mounted = false; console.log('[ReactNativePopupRenderer] survey completed:', { surveyId: this.lastSurveyId, data }); this.lastSurveyId = null; } hide(): void { if (!this.mounted) return; this.mounted = false; console.log('[ReactNativePopupRenderer] hide survey:', this.lastSurveyId); this.lastSurveyId = null; }}
The built-in ReactNativePopupRenderer is a stub implementation. You’ll need to connect it to your React Native UI layer using events, context, or a state management solution.
Use Modal Components: React Native’s Modal component is ideal for displaying surveys
Handle Lifecycle: Clean up event listeners when components unmount
Test on Both Platforms: Ensure your implementation works on iOS and Android
Consider Navigation: Handle popups gracefully when users navigate between screens
Respect Platform Guidelines: Follow iOS and Android UI/UX guidelines for modals