This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
cool-pdf is an Expo module for displaying PDFs in React Native applications. The module provides a native view component that wraps platform-specific PDF rendering capabilities for iOS, Android, and web.
It's intended to be a drop-in replacement for react-native-pdf, so we need to maintain parity over the long term.
This is an Expo module built using expo-module-scripts. The architecture follows Expo's module pattern:
- CoolPdfView.tsx: React component that wraps the native view using
requireNativeView('CoolPdf') - CoolPdfModule.ts: Native module interface using
requireNativeModule('CoolPdf') - CoolPdf.types.ts: TypeScript type definitions for props and events
- index.ts: Main entry point that re-exports the view and module
- CoolPdfModule.swift: Module definition using Expo's
Moduleclass- Defines the View, Props, and Events for iOS
- Currently uses
WKWebViewas placeholder (will be replaced with PDFKit)
- CoolPdfView.swift: iOS view implementation extending
ExpoView
- CoolPdfModule.kt: Module definition using Expo's Kotlin DSL
- Defines the View, Props, and Events for Android
- Currently uses
WebViewas placeholder (will be replaced with PdfRenderer)
- CoolPdfView.kt: Android view implementation extending
ExpoView
- CoolPdfModule.web.ts: Web-specific module implementation
- CoolPdfView.web.tsx: Web-specific view implementation
Build and test the module:
npm run build # Build the TypeScript code
npm run clean # Clean build artifacts
npm run lint # Lint the codebase
npm run test # Run testsWork with the example app:
# Open native projects
npm run open:ios # Opens iOS project in Xcode
npm run open:android # Opens Android project in Android Studio
# Run the example app (from example/ directory)
cd example
npx expo start # Start Expo dev server
npx expo prebuild --clean # Run Expo prebuild for dev build
npx expo run:ios # Run on iOS simulator
npx expo run:android # Run on Android emulatorThe expo-module.config.json defines platform support and native module names:
- Platforms: apple, android, web
- iOS module:
CoolPdfModule - Android module:
expo.modules.coolpdf.CoolPdfModule
When implementing the PDF view:
- Both iOS and Android views extend
ExpoView(required for proper styling support like border radius) - Props are defined in the Module's
View()definition usingProp() - Events are defined using
Events()and dispatched withEventDispatcherin the view class - The view lifecycle is managed by Expo's module system
- The TypeScript types in
CoolPdf.types.tsmust match the native prop definitions
The implementation should follow patterns from react-native-pdf (https://github.com/wonday/react-native-pdf), particularly:
- PDF rendering approach for iOS (PDFKit) and Android (PdfRenderer)
- Common props like page navigation, zoom, scale
- Events for load completion, page changes, errors
- Use Expo docs: https://docs.expo.dev/modules/native-view-tutorial/
Important: The react-native-pdf reference implementation is available in example/node_modules/react-native-pdf/. Check there first for implementation details, API references, and examples. Only search the web for react-native-pdf when checking for open issues, PRs, or other GitHub-specific information.
The example app includes a scenario-based testing system to compare CoolPDF with react-native-pdf. Use the scaffold script to create new scenarios:
node scripts/create-scenario.js --name "Your Scenario Name" --category basic --id your-scenario-idCategories: basic, navigation, zoom
The script creates:
- Scenario metadata file (e.g.,
YourScenarioName.ts) - CoolPDF screen implementation
- react-native-pdf screen implementation
- Automatically updates navigation and routing
After running, edit the generated files to add:
- Scenario description and expected behavior
- PDF component props for both implementations
- Any custom event handlers
See scripts/README.md for detailed usage.