Skip to content

Commit 48c637f

Browse files
change name of the annotation props to support backward compatibility
1 parent 47cdfd7 commit 48c637f

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

android/src/main/java/com/alpha0010/pdf/PdfViewManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ class PdfViewManager(private val pdfMutex: Lock) : BaseViewManager<PdfView, PdfV
4141
/**
4242
* Set annotation from a PAS v1 JSON string
4343
*/
44-
@ReactProp(name = "annotation")
44+
@ReactProp(name = "annotationStr")
4545
fun setAnnotation(view: PdfView, source: String?) = view.setAnnotation(source ?: "")
4646

4747
/**
4848
* Set annotation from file containing a PAS v1 JSON string
4949
*/
50-
@ReactProp(name = "annotationPath")
50+
@ReactProp(name = "annotation")
5151
fun setAnnotationWithPath(view: PdfView, source: String?) = view.setAnnotation(source ?: "", true)
5252

5353
/**

ios/PdfView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ enum ResizeMode: String {
44
}
55

66
class PdfView: UIView {
7-
@objc var annotation = "" { didSet { loadAnnotation() } }
8-
@objc var annotationPath = "" { didSet { loadAnnotation(file: true) } }
7+
@objc var annotationStr = "" { didSet { loadAnnotation() } }
8+
@objc var annotation = "" { didSet { loadAnnotation(file: true) } }
99
@objc var page: NSNumber = 0 { didSet { renderPdf() } }
1010
@objc var resizeMode = ResizeMode.CONTAIN.rawValue { didSet { validateResizeMode() } }
1111
@objc var source = "" { didSet { renderPdf() } }
@@ -25,7 +25,7 @@ class PdfView: UIView {
2525
}
2626

2727
private func loadAnnotation(file: Bool = false) {
28-
guard !annotation.isEmpty || !annotationPath.isEmpty else {
28+
guard !annotation.isEmpty || !annotationStr.isEmpty else {
2929
if !annotationData.isEmpty {
3030
annotationData.removeAll()
3131
renderPdf()
@@ -37,10 +37,10 @@ class PdfView: UIView {
3737
do {
3838
var data:Data;
3939
if (file) {
40-
data = try Data(contentsOf: URL(fileURLWithPath: annotationPath))
40+
data = try Data(contentsOf: URL(fileURLWithPath: annotation))
4141
}
4242
else {
43-
data = annotation.data(using: .utf8)!;
43+
data = annotationStr.data(using: .utf8)!;
4444
}
4545
annotationData = try decoder.decode([AnnotationPage].self, from: data)
4646
} catch {
@@ -244,4 +244,4 @@ class PdfView: UIView {
244244
}
245245
dispatcher(["width": pageWidth, "height": pageHeight])
246246
}
247-
}
247+
}

ios/PdfViewManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@interface RCT_EXTERN_REMAP_MODULE(RNPdfView, PdfViewManager, RCTViewManager)
44

55
RCT_EXPORT_VIEW_PROPERTY(annotation, NSString)
6-
RCT_EXPORT_VIEW_PROPERTY(annotationPath, NSString)
6+
RCT_EXPORT_VIEW_PROPERTY(annotationStr, NSString)
77
RCT_EXPORT_VIEW_PROPERTY(page, NSNumber)
88
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString)
99
RCT_EXPORT_VIEW_PROPERTY(source, NSString)

src/Pdf.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ type PdfProps = BaseListProps & {
108108
/**
109109
* PAS v1 annotation JSON string.
110110
*/
111-
annotation?: string;
111+
annotationStr?: string;
112112

113113
/**
114114
* Path to annotation data.
115115
*/
116-
annotationPath?: string;
116+
annotation?: string;
117117

118118
/**
119119
* Callback to handle errors.
@@ -319,15 +319,15 @@ export const Pdf = forwardRef((props: PdfProps, ref: React.Ref<PdfRef>) => {
319319
<View>
320320
<PdfView
321321
annotation={props.annotation}
322-
annotationPath={props.annotationPath}
322+
annotationStr={props.annotationStr}
323323
page={index}
324324
source={source}
325325
style={styles.page}
326326
/>
327327
</View>
328328
</View>
329329
),
330-
[maxPageHeight, props.annotation, props.annotationPath, source]
330+
[maxPageHeight, props.annotation, props.annotationStr, source]
331331
);
332332

333333
return (

src/PdfView.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type ResizeMode = 'contain' | 'fitWidth';
1515

1616
type PdfViewNativeProps = {
1717
annotation?: string;
18-
annotationPath?: string;
18+
annotationStr?: string;
1919
onLayout?: (event: LayoutChangeEvent) => void;
2020
onPdfError: (event: NativeSyntheticEvent<ErrorEvent>) => void;
2121
onPdfLoadComplete: (event: NativeSyntheticEvent<LoadCompleteEvent>) => void;
@@ -29,12 +29,12 @@ export type PdfViewProps = {
2929
/**
3030
* PAS v1 annotation JSON string.
3131
*/
32-
annotation?: string;
32+
annotationStr?: string;
3333

3434
/**
3535
* Path to annotation data.
3636
*/
37-
annotationPath?: string;
37+
annotation?: string;
3838
/**
3939
* Callback to handle errors.
4040
*/
@@ -110,8 +110,8 @@ export function PdfView(props: PdfViewProps) {
110110

111111
return (
112112
<PdfViewNative
113-
annotation={props.annotation}
114-
annotationPath={asPath(props.annotationPath)}
113+
annotation={asPath(props.annotation)}
114+
annotationStr={props.annotationStr}
115115
onLayout={onLayout}
116116
onPdfError={onPdfError}
117117
onPdfLoadComplete={onPdfLoadComplete}

0 commit comments

Comments
 (0)