// YetiPoll for React Native. Add this file to your project.
//
// Needs: react-native-webview
//
//
//
// Pass `signature` when your app requires signed wall links: compute it on
// your server (HMAC-SHA256 of the user id with your secret key).
import React, { useEffect, useRef } from 'react';
import { AppState, Linking, StyleProp, ViewStyle } from 'react-native';
import { WebView } from 'react-native-webview';
export function yetiPollWallUrl(appKey: string, userId: string, signature?: string): string {
let url = `https://yetipoll.com/wall?app=${encodeURIComponent(appKey)}&user=${encodeURIComponent(userId)}`;
if (signature) {
url += `&sig=${encodeURIComponent(signature)}`;
}
return url;
}
type Props = { appKey: string; userId: string; signature?: string; style?: StyleProp };
export function YetiPollWall({ appKey, userId, signature, style }: Props) {
const web = useRef(null);
// Fresh surveys when the user comes back from one.
useEffect(() => {
const subscription = AppState.addEventListener('change', (state) => {
if (state === 'active') {
web.current?.reload();
}
});
return () => subscription.remove();
}, []);
return (
{
const onWall = request.url.startsWith('https://yetipoll.com/') && !request.url.includes('/wall/go/');
if (!onWall) {
Linking.openURL(request.url);
}
return onWall;
}}
/>
);
}