Skip to content

Commit 1b07a36

Browse files
committed
refactor: unify some code styles
1 parent 95c79a3 commit 1b07a36

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class PdfView(context: Context, private val pdfMutex: Lock) : View(context) {
4545
private var mSource = ""
4646
private val mViewRects = List(SLICES) { Rect() }
4747

48-
fun setAnnotation(source: String, file: Boolean = false) {
48+
fun setAnnotation(source: String, file: Boolean) {
4949
if (source.isEmpty()) {
5050
if (mAnnotation.isNotEmpty()) {
5151
mAnnotation = emptyList()
@@ -55,10 +55,10 @@ class PdfView(context: Context, private val pdfMutex: Lock) : View(context) {
5555
}
5656

5757
try {
58-
if (file) {
59-
mAnnotation = Json.decodeFromString(File(source).readText())
58+
mAnnotation = if (file) {
59+
Json.decodeFromString(File(source).readText())
6060
} else {
61-
mAnnotation = Json.decodeFromString(source);
61+
Json.decodeFromString(source)
6262
}
6363
mDirty = true
6464
} catch (e: Exception) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ class PdfViewManager(private val pdfMutex: Lock) : BaseViewManager<PdfView, PdfV
4242
* Set annotation from a PAS v1 JSON string
4343
*/
4444
@ReactProp(name = "annotationStr")
45-
fun setAnnotation(view: PdfView, source: String?) = view.setAnnotation(source ?: "")
45+
fun setAnnotationStr(view: PdfView, source: String?) =
46+
view.setAnnotation(source ?: "", file = false)
4647

4748
/**
4849
* Set annotation from file containing a PAS v1 JSON string
4950
*/
5051
@ReactProp(name = "annotation")
51-
fun setAnnotationWithPath(view: PdfView, source: String?) = view.setAnnotation(source ?: "", true)
52+
fun setAnnotation(view: PdfView, source: String?) =
53+
view.setAnnotation(source ?: "", file = true)
5254

5355
/**
5456
* Page (0-indexed) of document to display.

ios/PdfView.swift

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

66
class PdfView: UIView {
7-
@objc var annotationStr = "" { didSet { loadAnnotation() } }
7+
@objc var annotationStr = "" { didSet { loadAnnotation(file: false) } }
88
@objc var annotation = "" { didSet { loadAnnotation(file: true) } }
99
@objc var page: NSNumber = 0 { didSet { renderPdf() } }
1010
@objc var resizeMode = ResizeMode.CONTAIN.rawValue { didSet { validateResizeMode() } }
@@ -24,7 +24,7 @@ class PdfView: UIView {
2424
super.layoutSubviews()
2525
}
2626

27-
private func loadAnnotation(file: Bool = false) {
27+
private func loadAnnotation(file: Bool) {
2828
guard !annotation.isEmpty || !annotationStr.isEmpty else {
2929
if !annotationData.isEmpty {
3030
annotationData.removeAll()
@@ -35,7 +35,7 @@ class PdfView: UIView {
3535

3636
let decoder = JSONDecoder()
3737
do {
38-
var data:Data;
38+
let data: Data;
3939
if (file) {
4040
data = try Data(contentsOf: URL(fileURLWithPath: annotation))
4141
}

src/PdfView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export type PdfViewProps = {
3535
* Path to annotation data.
3636
*/
3737
annotation?: string;
38+
3839
/**
3940
* Callback to handle errors.
4041
*/

0 commit comments

Comments
 (0)