Keep LITE exports clean of PRO looks, and gate CREATE, FAVORITED and + SAVE behind PRO

LITE previews every look and feature but export/render is blocked while a PRO
look is in use, and every LITE export carries the RECIPESCAM mark. Keys are
generated offline (FNV-1a checksum over a fixed secret, 16 chars from a
no-ambiguity alphabet) and activate one machine or a thousand: nothing is bound
to a device, so revoking a leaked key needs Play Billing plus server validation.

CREATE, FAVORITED, the star chip and the TopBar + SAVE now answer with a PRO
prompt instead of a silent no-op; CREATE still drafts and applies the look so
LITE can try it, it just cannot persist.

The SETTINGS card also lifts above the keyboard now: RN Modal is its own dialog
window, so the IME never resizes or pans it and the UNLOCK row was sitting under
the keys.
This commit is contained in:
2026-09-12 11:21:14 +07:00
parent a662674478
commit 59e2719245
4 changed files with 313 additions and 10 deletions
+80 -7
View File
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { View, Text, Modal, TouchableOpacity } from 'react-native';
import React, { useEffect, useState } from 'react';
import { View, Text, Keyboard, Modal, ScrollView, TouchableOpacity, TextInput } from 'react-native';
import * as Haptics from 'expo-haptics';
import { X, Volume2, Info, ChevronRight, MapPin, Settings as SettingsIcon } from 'lucide-react-native';
import { AspectRatio, MeterMode, ShutterSound, StartupMode } from '../types';
@@ -35,6 +35,11 @@ interface SettingsModalProps {
onGpsEnabled: (enabled: boolean) => void;
startupMode: StartupMode;
onStartupMode: (mode: StartupMode) => void;
// Lite vs PRO. The unlock key is verified in App (the entitlement module owns
// the maths) and comes back false for a bad key, which is all this sheet needs
// to know — let alone store.
pro: boolean;
onUnlock: (key: string) => Promise<boolean>;
}
function ChipRow({ chips }: { chips: Chip[] }) {
@@ -94,20 +99,40 @@ export default function SettingsModal({
onGpsEnabled,
startupMode,
onStartupMode,
pro,
onUnlock,
}: SettingsModalProps) {
const [showCredits, setShowCredits] = useState(false);
const [keyDraft, setKeyDraft] = useState('');
const [keyError, setKeyError] = useState(false);
// The RN Modal is its own dialog window, so the IME does not resize it and
// the card ends up under the keyboard. Track the keyboard height and lift the
// card by that much instead.
const [kb, setKb] = useState(0);
useEffect(() => {
const show = Keyboard.addListener('keyboardDidShow', (e) => setKb(e.endCoordinates.height));
const hide = Keyboard.addListener('keyboardDidHide', () => setKb(0));
return () => {
show.remove();
hide.remove();
};
}, []);
return (
<Modal visible={visible} transparent animationType="fade" onRequestClose={onClose}>
<View className="flex-1 bg-black/70 items-center justify-center px-6">
<View className="flex-1 bg-black/70 items-center justify-center px-6" style={{ paddingBottom: kb }}>
<TouchableOpacity
className="absolute inset-0"
activeOpacity={1}
onPress={onClose}
accessibilityLabel="Close settings"
/>
<View
className="w-full max-w-md rounded-2xl border border-zinc-800/70 p-5 pb-6 space-y-5"
style={{ backgroundColor: 'rgba(8,8,10,0.97)' }}
<ScrollView
className="w-full max-w-md rounded-2xl border border-zinc-800/70"
style={{ maxHeight: '100%', flexGrow: 0 }}
contentContainerClassName="p-5 pb-6 space-y-5"
contentContainerStyle={{ backgroundColor: 'rgba(8,8,10,0.97)' }}
keyboardShouldPersistTaps="handled"
showsVerticalScrollIndicator={false}
>
<View className="flex-row items-center justify-between px-1">
<View className="flex-row items-center">
@@ -213,6 +238,54 @@ export default function SettingsModal({
<CameraOnlyNote cameraMode={cameraMode} />
</View>
{/* Lite vs PRO. Every look is free to preview and edit; the key buys
the export: no mark, and PRO presets/frames/watermarks allowed. */}
<View>
<SectionLabel>PRO</SectionLabel>
<ChipRow
chips={[
{ key: 'plan', label: pro ? 'PRO ACTIVE' : 'LITE', active: pro, disabled: true, onPress: () => {} },
]}
/>
{!pro && (
<View className="flex-row items-center mt-2">
<TextInput
value={keyDraft}
onChangeText={(t) => {
setKeyDraft(t);
setKeyError(false);
}}
placeholder="XXXX-XXXX-XXXX-XXXX"
placeholderTextColor="#52525b"
autoCapitalize="characters"
autoCorrect={false}
className={`flex-1 rounded-md border bg-black/40 px-3 py-2 font-mono text-xs font-bold ${
keyError ? 'border-red-500/70 text-red-400' : 'border-zinc-700 text-zinc-200'
}`}
/>
<TouchableOpacity
onPress={async () => {
haptic();
const ok = await onUnlock(keyDraft);
setKeyError(!ok);
if (ok) setKeyDraft('');
}}
activeOpacity={0.7}
className="ml-2 rounded-md border border-amber-500/70 bg-amber-500/15 px-3 py-2"
>
<Text className="font-mono text-[11px] font-bold text-amber-500">UNLOCK</Text>
</TouchableOpacity>
</View>
)}
<Text className="text-zinc-600 font-mono text-[10px] mt-1.5 ml-1">
{keyError
? 'That key is not valid. Check all 16 characters.'
: pro
? 'Every look exports clean: no mark, no limits. Thanks!'
: 'LITE is free forever. Any preset, frame and watermark can be previewed and edited, but a PRO look cannot be exported and every export carries the RECIPESCAM mark. Enter your key to lift both.'}
</Text>
</View>
{/* About & open-source credits */}
<View>
<TouchableOpacity
@@ -235,7 +308,7 @@ export default function SettingsModal({
App info + third-party open-source licenses.
</Text>
</View>
</View>
</ScrollView>
</View>
<CreditsModal visible={showCredits} onClose={() => setShowCredits(false)} />
</Modal>
+86
View File
@@ -0,0 +1,86 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import { FrameId } from '../types';
// Lite (free, forever) vs PRO (one unlock key). The gate is on the FILE, not on
// the preview: a Lite user may pick any preset, frame or watermark, compose
// with it and compare before/after — only the render/export of that look is
// held back, and every Lite export carries the mark below.
const PRO_KEY = '@camrecipe_pro:pro';
// Frames on the Lite side: the plain export only. The three printed looks are
// PRO (the artwork/card geometry is the paid half of the FRAME tab).
export const PRO_FRAMES: FrameId[] = ['classic-white', 'polaroid', 'wallframe'];
// Presets: the eight film SIMS are free (a base-filter matrix is the camera's
// own look); a saved RECIPE — bundled or user-created — is a dialled-in look
// and belongs to PRO. Ids are `sim-*` for sims, anything else for recipes.
export const isFreeRecipe = (id: string | null | undefined): boolean =>
!id || id.startsWith('sim-');
// Burned into every Lite export, bottom-right of the photo/frame area. Fractions
// of the stamp canvas, same space the custom mark uses.
export const LITE_MARK = {
text: 'RECIPESCAM',
x: 0.55,
y: 0.94,
color: '#ffffff',
size: 0.8,
};
export interface Look {
recipeId?: string | null;
frame: FrameId;
customWm: boolean;
}
// The first PRO feature a look is using, or null when it is Lite-clean. One
// string, so the caller can name it back to the user in the alert.
export function proLookInUse(look: Look): string | null {
if (!isFreeRecipe(look.recipeId)) return 'A PRO preset';
if (PRO_FRAMES.includes(look.frame)) return 'A PRO frame';
if (look.customWm) return 'The custom watermark';
return null;
}
export const loadPro = async (): Promise<boolean> =>
(await AsyncStorage.getItem(PRO_KEY)) === '1';
// ---- unlock key -------------------------------------------------------------
// Offline product key: 12 payload chars + 4 checksum chars, any punctuation
// ignored (`XXXX-XXXX-XXXX-XXXX`). No server, no clock — whoever buys gets a key
// from tools/keygen.mjs. A reverse engineer can mint their own: that is the
// ceiling of a client-only check. Move to Play Billing + server validation when
// the app ships on Play (ponytail).
// Keep KEY_ALPHABET / KEY_SECRET / checksum byte-identical to tools/keygen.mjs.
const KEY_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
const KEY_SECRET = 'recipes-cam-key-2026';
const checksum = (payload: string): number => {
let h = 0x811c9dc5; // FNV-1a 32
const src = KEY_SECRET + payload;
for (let i = 0; i < src.length; i++) {
h ^= src.charCodeAt(i);
h = Math.imul(h, 0x01000193) >>> 0;
}
return h & 0xfffff; // low 20 bits -> 4 chars of 5 bits
};
export function keyIsValid(raw: string): boolean {
const s = (raw || '').toUpperCase().replace(/[^A-Z0-9]/g, '');
if (s.length !== 16) return false;
for (let i = 0; i < 16; i++) if (KEY_ALPHABET.indexOf(s[i]) < 0) return false;
const bits = checksum(s.slice(0, 12));
for (let i = 0; i < 4; i++) {
if (KEY_ALPHABET[(bits >>> (i * 5)) & 31] !== s[12 + i]) return false;
}
return true;
}
// Returns false for a wrong key; on success PRO is persisted and every later
// export stops being marked.
export async function activatePro(raw: string): Promise<boolean> {
if (!keyIsValid(raw)) return false;
await AsyncStorage.setItem(PRO_KEY, '1');
return true;
}