@@ -30,34 +30,10 @@ @implementation RCTConvert (PSPDFAnnotation)
30
30
if ([annotation isKindOfClass: [PSPDFFormElement class ]]) {
31
31
PSPDFFormElement *formElement = (PSPDFFormElement *)annotation;
32
32
annotationDictionary[@" isRequired" ] = @(formElement.isRequired );
33
- NSDictionary *formElementJSON;
34
-
35
- if ([formElement isKindOfClass: [PSPDFButtonFormElement class ]]) {
36
- formElementJSON = [RCTConvert buttonFormElementToJSON: (PSPDFButtonFormElement *)formElement];
37
- NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
38
- mutableJSON[@" type" ] = @" button" ;
39
- formElementJSON = [mutableJSON copy ];
40
- } else if ([formElement isKindOfClass: [PSPDFChoiceFormElement class ]]) {
41
- formElementJSON = [RCTConvert choiceFormElementToJSON: (PSPDFChoiceFormElement *)formElement];
42
- NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
43
- mutableJSON[@" type" ] = @" choice" ;
44
- formElementJSON = [mutableJSON copy ];
45
- } else if ([formElement isKindOfClass: [PSPDFSignatureFormElement class ]]) {
46
- formElementJSON = [RCTConvert signatureFormElementToJSON: (PSPDFSignatureFormElement *)formElement];
47
- NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
48
- mutableJSON[@" type" ] = @" signature" ;
49
- formElementJSON = [mutableJSON copy ];
50
- } else if ([formElement isKindOfClass: [PSPDFTextFieldFormElement class ]]) {
51
- formElementJSON = [RCTConvert textFieldFormElementToJSON: (PSPDFTextFieldFormElement *)formElement];
52
- NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
53
- mutableJSON[@" type" ] = @" textField" ;
54
- formElementJSON = [mutableJSON copy ];
55
- } else {
56
- // Skip unknown form element types
57
- continue ;
33
+ NSDictionary *formElementJSON = [RCTConvert formElementToJSON: formElement];
34
+ if (formElementJSON != nil ) {
35
+ annotationDictionary[@" formElement" ] = formElementJSON;
58
36
}
59
-
60
- annotationDictionary[@" formElement" ] = formElementJSON;
61
37
}
62
38
63
39
if (annotationDictionary) {
@@ -72,6 +48,36 @@ @implementation RCTConvert (PSPDFAnnotation)
72
48
return [annotationsJSON copy ];
73
49
}
74
50
51
+ + (NSDictionary *)formElementToJSON : (PSPDFFormElement *)formElement {
52
+ NSDictionary *formElementJSON;
53
+
54
+ if ([formElement isKindOfClass: [PSPDFButtonFormElement class ]]) {
55
+ formElementJSON = [RCTConvert buttonFormElementToJSON: (PSPDFButtonFormElement *)formElement];
56
+ NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
57
+ mutableJSON[@" type" ] = @" button" ;
58
+ formElementJSON = [mutableJSON copy ];
59
+ } else if ([formElement isKindOfClass: [PSPDFChoiceFormElement class ]]) {
60
+ formElementJSON = [RCTConvert choiceFormElementToJSON: (PSPDFChoiceFormElement *)formElement];
61
+ NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
62
+ mutableJSON[@" type" ] = @" choice" ;
63
+ formElementJSON = [mutableJSON copy ];
64
+ } else if ([formElement isKindOfClass: [PSPDFSignatureFormElement class ]]) {
65
+ formElementJSON = [RCTConvert signatureFormElementToJSON: (PSPDFSignatureFormElement *)formElement];
66
+ NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
67
+ mutableJSON[@" type" ] = @" signature" ;
68
+ formElementJSON = [mutableJSON copy ];
69
+ } else if ([formElement isKindOfClass: [PSPDFTextFieldFormElement class ]]) {
70
+ formElementJSON = [RCTConvert textFieldFormElementToJSON: (PSPDFTextFieldFormElement *)formElement];
71
+ NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
72
+ mutableJSON[@" type" ] = @" textField" ;
73
+ formElementJSON = [mutableJSON copy ];
74
+ } else {
75
+ return nil ; // Return nil if no conditions match
76
+ }
77
+
78
+ return formElementJSON;
79
+ }
80
+
75
81
+ (NSDictionary *)instantJSONFromFormElement : (PSPDFFormElement *)formElement error : (NSError **)error {
76
82
NSMutableDictionary *formElementJSON = [NSMutableDictionary new ];
77
83
@@ -83,6 +89,16 @@ + (NSDictionary *)instantJSONFromFormElement:(PSPDFFormElement *)formElement err
83
89
if (formElementData) {
84
90
NSMutableDictionary *formElementDictionary = [[NSJSONSerialization JSONObjectWithData: formElementData options: kNilOptions error: error] mutableCopy ];
85
91
[formElementJSON addEntriesFromDictionary: additionalInfo];
92
+
93
+ // If this is a Widget annotation, add the FormElement
94
+ if ([formElement isKindOfClass: [PSPDFFormElement class ]]) {
95
+ formElementDictionary[@" isRequired" ] = @(formElement.isRequired );
96
+ NSDictionary *formElementJSON = [RCTConvert formElementToJSON: formElement];
97
+ if (formElementJSON != nil ) {
98
+ formElementDictionary[@" formElement" ] = formElementJSON;
99
+ }
100
+ }
101
+
86
102
if (formElementDictionary) {
87
103
[formElementJSON addEntriesFromDictionary: formElementDictionary];
88
104
}
0 commit comments