Skip to content

Commit 76ff9cd

Browse files
darrenchanngithub-actions[bot]brandenfung2
authored
[iOS/Android] Add config tools for checkmark, crossmark, dot (#672)
* android and js implementation * adding config * android full implementation needs ios now * ios implementation * redundant import * Update package.json * Update package.json * Update package.json * weird package.json spacing * Update package.json still weird spacing * PR comments - make name more clear * Updating package version * tool permissions * Updating package version * Add support for setTool and disableTools on Android * Updating package version * Revert version * Updating package version --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: brandenfung2 <bfung@pdftron.com>
1 parent acd40fa commit 76ff9cd

File tree

7 files changed

+111
-2
lines changed

7 files changed

+111
-2
lines changed

android/src/main/java/com/pdftron/reactnative/utils/Constants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ public final class Constants {
137137
public static final String TOOL_ANNOTATION_CREATE_FREE_SPACING_TEXT = "AnnotationCreateFreeSpacingText";
138138
public static final String TOOL_INSERT_PAGE = "InsertPage";
139139
public static final String TOOL_FORM_FILL = "FormFill";
140+
public static final String TOOL_ANNOTATION_CREATE_CHECK_MARK_STAMP = "AnnotationCreateCheckMarkStamp";
141+
public static final String TOOL_ANNOTATION_CREATE_CROSS_MARK_STAMP = "AnnotationCreateCrossMarkStamp";
142+
public static final String TOOL_ANNOTATION_CREATE_DOT_STAMP = "AnnotationCreateDotStamp";
140143
public static final String TOOL_COUNT_TOOL = "AnnotationCountTool";
141144

142145
// Field types

android/src/main/java/com/pdftron/reactnative/views/DocumentView.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import com.pdftron.pdf.tools.Pan;
7979
import com.pdftron.pdf.tools.QuickMenu;
8080
import com.pdftron.pdf.tools.QuickMenuItem;
81+
import com.pdftron.pdf.tools.RubberStampCreate;
8182
import com.pdftron.pdf.tools.TextSelect;
8283
import com.pdftron.pdf.tools.Tool;
8384
import com.pdftron.pdf.tools.ToolManager;
@@ -138,6 +139,7 @@ public class DocumentView extends com.pdftron.pdf.controls.DocumentView2 {
138139
private ViewerConfig.Builder mBuilder;
139140

140141
private ArrayList<ToolManager.ToolMode> mDisabledTools = new ArrayList<>();
142+
private ArrayList<ToolbarButtonType> mDisabledButtonTypes = new ArrayList<>(); // used to disabled button types that are with specific a with explicit tool type (e.g. checkmark, dot, cross stamps)
141143

142144
private String mExportPath;
143145
private String mOpenUrlPath;
@@ -1224,6 +1226,9 @@ private void disableTools(ReadableArray args) {
12241226
ToolManager.ToolMode mode = convStringToToolMode(item);
12251227
if (mode != null) {
12261228
mDisabledTools.add(mode);
1229+
} else { // if there is no tool associated, then disable the button type instead
1230+
ToolbarButtonType buttonType = convStringToToolbarType(item);
1231+
mDisabledButtonTypes.add(buttonType);
12271232
}
12281233
}
12291234
}
@@ -1308,6 +1313,12 @@ private int convStringToAnnotType(String item) {
13081313
annotType = AnnotStyle.CUSTOM_ANNOT_TYPE_COUNT_MEASUREMENT;
13091314
} else if (TOOL_ANNOTATION_CREATE_FREE_TEXT_DATE.equals(item)) {
13101315
annotType = AnnotStyle.CUSTOM_ANNOT_TYPE_FREE_TEXT_DATE;
1316+
} else if (TOOL_ANNOTATION_CREATE_CHECK_MARK_STAMP.equals(item)) {
1317+
annotType = AnnotStyle.CUSTOM_ANNOT_TYPE_CHECKMARK_STAMP;
1318+
} else if (TOOL_ANNOTATION_CREATE_CROSS_MARK_STAMP.equals(item)) {
1319+
annotType = AnnotStyle.CUSTOM_ANNOT_TYPE_CROSS_STAMP;
1320+
} else if (TOOL_ANNOTATION_CREATE_DOT_STAMP.equals(item)) {
1321+
annotType = AnnotStyle.CUSTOM_ANNOT_TYPE_DOT_STAMP;
13111322
}
13121323
return annotType;
13131324
}
@@ -1394,6 +1405,15 @@ private String convAnnotTypeToString(Annot annot, int annotType) {
13941405
case AnnotStyle.CUSTOM_ANNOT_TYPE_FREE_TEXT_DATE:
13951406
annotString = TOOL_ANNOTATION_CREATE_FREE_TEXT_DATE;
13961407
break;
1408+
case AnnotStyle.CUSTOM_ANNOT_TYPE_CHECKMARK_STAMP:
1409+
annotString = TOOL_ANNOTATION_CREATE_CHECK_MARK_STAMP;
1410+
break;
1411+
case AnnotStyle.CUSTOM_ANNOT_TYPE_CROSS_STAMP:
1412+
annotString = TOOL_ANNOTATION_CREATE_CROSS_MARK_STAMP;
1413+
break;
1414+
case AnnotStyle.CUSTOM_ANNOT_TYPE_DOT_STAMP:
1415+
annotString = TOOL_ANNOTATION_CREATE_DOT_STAMP;
1416+
break;
13971417
default:
13981418
annotString = "";
13991419
break;
@@ -1514,6 +1534,12 @@ private ToolManager.ToolMode convStringToToolMode(String item) {
15141534
mode = ToolManager.ToolMode.COUNT_MEASUREMENT;
15151535
} else if (TOOL_ANNOTATION_CREATE_FREE_TEXT_DATE.equals(item)) {
15161536
mode = ToolManager.ToolMode.FREE_TEXT_DATE_CREATE;
1537+
} else if (TOOL_ANNOTATION_CREATE_CHECK_MARK_STAMP.equals(item)) {
1538+
mode = ToolManager.ToolMode.RUBBER_STAMPER;
1539+
} else if (TOOL_ANNOTATION_CREATE_CROSS_MARK_STAMP.equals(item)) {
1540+
mode = ToolManager.ToolMode.RUBBER_STAMPER;
1541+
} else if (TOOL_ANNOTATION_CREATE_DOT_STAMP.equals(item)) {
1542+
mode = ToolManager.ToolMode.RUBBER_STAMPER;
15171543
}
15181544
return mode;
15191545
}
@@ -1742,6 +1768,12 @@ private int convStringToButtonId(String item) {
17421768
buttonId = DefaultToolbars.ButtonId.CUSTOMIZE.value();
17431769
} else if (TOOL_ANNOTATION_CREATE_FREE_TEXT_DATE.equals(item)) {
17441770
buttonId = DefaultToolbars.ButtonId.DATE.value();
1771+
} else if (TOOL_ANNOTATION_CREATE_CHECK_MARK_STAMP.equals(item)) {
1772+
buttonId = DefaultToolbars.ButtonId.CHECKMARK.value();
1773+
} else if (TOOL_ANNOTATION_CREATE_CROSS_MARK_STAMP.equals(item)) {
1774+
buttonId = DefaultToolbars.ButtonId.CROSS.value();
1775+
} else if (TOOL_ANNOTATION_CREATE_DOT_STAMP.equals(item)) {
1776+
buttonId = DefaultToolbars.ButtonId.DOT.value();
17451777
}
17461778
return buttonId;
17471779
}
@@ -1903,6 +1935,12 @@ private ToolbarButtonType convStringToToolbarType(String item) {
19031935
buttonType = ToolbarButtonType.EDIT_TOOLBAR;
19041936
} else if (TOOL_ANNOTATION_CREATE_FREE_TEXT_DATE.equals(item)) {
19051937
buttonType = ToolbarButtonType.DATE;
1938+
} else if (TOOL_ANNOTATION_CREATE_CHECK_MARK_STAMP.equals(item)) {
1939+
buttonType = ToolbarButtonType.CHECKMARK;
1940+
} else if (TOOL_ANNOTATION_CREATE_CROSS_MARK_STAMP.equals(item)) {
1941+
buttonType = ToolbarButtonType.CROSS;
1942+
} else if (TOOL_ANNOTATION_CREATE_DOT_STAMP.equals(item)) {
1943+
buttonType = ToolbarButtonType.DOT;
19061944
}
19071945
return buttonType;
19081946
}
@@ -3064,6 +3102,12 @@ public void onTabDocumentLoaded(String tag) {
30643102
mPdfViewCtrlTabHostFragment.toolbarButtonVisibility(ToolbarButtonType.ADD_PAGE, false);
30653103
}
30663104

3105+
if (!mDisabledButtonTypes.isEmpty()) {
3106+
for (ToolbarButtonType disabledButtonType : mDisabledButtonTypes) {
3107+
mPdfViewCtrlTabHostFragment.toolbarButtonVisibility(disabledButtonType, false);
3108+
}
3109+
}
3110+
30673111
if (!mCollabEnabled && getToolManager() != null) {
30683112
getToolManager().setStickyNoteShowPopup(!isOverrideAction(KEY_CONFIG_STICKY_NOTE_SHOW_POP_UP));
30693113
}
@@ -3974,9 +4018,26 @@ public void getFieldsForPage(int pageNumber, WritableArray fieldsArray) {
39744018
public void setToolMode(String item) {
39754019
if (getToolManager() != null) {
39764020
ToolManager.ToolMode mode = convStringToToolMode(item);
4021+
ToolbarButtonType buttonType = convStringToToolbarType(item);
4022+
39774023
Tool tool = (Tool) getToolManager().createTool(mode, null);
39784024
boolean continuousAnnot = PdfViewCtrlSettingsManager.getContinuousAnnotationEdit(getContext());
39794025
tool.setForceSameNextToolMode(continuousAnnot);
4026+
if (buttonType != null && mode == ToolManager.ToolMode.RUBBER_STAMPER && tool instanceof RubberStampCreate) { // check whether dot, checkmark, or cross
4027+
RubberStampCreate rubberStampCreateTool = (RubberStampCreate) tool;
4028+
switch (buttonType) {
4029+
case DOT:
4030+
rubberStampCreateTool.setStampName(RubberStampCreate.sDOT_LABEL);
4031+
break;
4032+
case CROSS:
4033+
rubberStampCreateTool.setStampName(RubberStampCreate.sCROSS_LABEL);
4034+
break;
4035+
case CHECKMARK:
4036+
rubberStampCreateTool.setStampName(RubberStampCreate.sCHECK_MARK_LABEL);
4037+
break;
4038+
}
4039+
}
4040+
39804041
getToolManager().setTool(tool);
39814042
}
39824043
}

ios/RNTPTDocumentView.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ static NSString * const PTFormCreateRadioFieldToolKey = @"FormCreateRadioField";
101101
static NSString * const PTFormCreateComboBoxFieldToolKey = @"FormCreateComboBoxField";
102102
static NSString * const PTFormCreateListBoxFieldToolKey = @"FormCreateListBoxField";
103103
static NSString * const PTInsertPageToolKey = @"InsertPage";
104-
static NSString *const PTFormFillToolKey = @"FormFill";
104+
static NSString * const PTFormFillToolKey = @"FormFill";
105+
static NSString * const PTAnnotationCreateCheckMarkStampKey = @"AnnotationCreateCheckMarkStamp";
106+
static NSString * const PTAnnotationCreateCrossMarkStampKey = @"AnnotationCreateCrossMarkStamp";
107+
static NSString * const PTAnnotationCreateDotStampKey = @"AnnotationCreateDotStamp";
105108

106109
static NSString * const PTHiddenAnnotationFlagKey = @"hidden";
107110
static NSString * const PTInvisibleAnnotationFlagKey = @"invisible";

ios/RNTPTDocumentView.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,15 @@ - (void)setToolsPermission:(NSArray<NSString *> *)stringsArray toValue:(BOOL)val
972972
else if([string isEqualToString:PTInsertFromDocumentButton]){
973973
[addPagesItems removeObject:documentViewController.addPagesViewController.addDocumentPagesButtonItem];
974974
}
975+
else if([string isEqualToString:PTAnnotationCreateCheckMarkStampKey]) {
976+
// TODO
977+
}
978+
else if([string isEqualToString:PTAnnotationCreateCrossMarkStampKey]) {
979+
// TODO
980+
}
981+
else if([string isEqualToString:PTAnnotationCreateDotStampKey]) {
982+
// TODO
983+
}
975984
}
976985
}
977986
if([addPagesItems count] == 0){
@@ -1130,6 +1139,15 @@ - (void)setToolMode:(NSString *)toolMode
11301139
}
11311140
else if ( [toolMode isEqualToString:PTAnnotationCreateFreeTextDateToolKey]) {
11321141
toolClass = [PTDateTextCreate class];
1142+
}
1143+
else if ( [toolMode isEqualToString:PTAnnotationCreateCheckMarkStampKey] ) {
1144+
toolClass = [PTCheckMarkStampCreate class];
1145+
}
1146+
else if ( [toolMode isEqualToString:PTAnnotationCreateCrossMarkStampKey] ) {
1147+
toolClass = [PTCrossMarkStampCreate class];
1148+
}
1149+
else if ( [toolMode isEqualToString:PTAnnotationCreateDotStampKey] ) {
1150+
toolClass = [PTDotStampCreate class];
11331151
}
11341152

11351153
if (toolClass) {
@@ -5852,6 +5870,15 @@ + (Class)toolClassForKey:(NSString *)key
58525870
else if ([key isEqualToString:PTAnnotationCreateFreeTextDateToolKey]) {
58535871
return [PTDateTextCreate class];
58545872
}
5873+
else if ( [key isEqualToString:PTAnnotationCreateCheckMarkStampKey] ) {
5874+
return [PTCheckMarkStampCreate class];
5875+
}
5876+
else if ( [key isEqualToString:PTAnnotationCreateCrossMarkStampKey] ) {
5877+
return [PTCrossMarkStampCreate class];
5878+
}
5879+
else if ( [key isEqualToString:PTAnnotationCreateDotStampKey] ) {
5880+
return [PTDotStampCreate class];
5881+
}
58555882

58565883
if (@available(iOS 13.1, *)) {
58575884
if ([key isEqualToString:PTPencilKitDrawingToolKey]) {
@@ -5984,6 +6011,15 @@ + (NSString *)keyForToolClass:(Class)toolClass
59846011
else if (toolClass == [PTRadioButtonCreate class]) {
59856012
return PTFormCreateRadioFieldToolKey;
59866013
}
6014+
else if (toolClass == [PTCheckMarkStampCreate class]) {
6015+
return PTAnnotationCreateCheckMarkStampKey;
6016+
}
6017+
else if (toolClass == [PTCrossMarkStampCreate class]) {
6018+
return PTAnnotationCreateCrossMarkStampKey;
6019+
}
6020+
else if (toolClass == [PTDotStampCreate class]) {
6021+
return PTAnnotationCreateDotStampKey;
6022+
}
59876023

59886024
if (@available(iOS 13.1, *)) {
59896025
if (toolClass == [PTPencilDrawingCreate class]) {

lib/src/Config/Config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ export const Config = {
104104
formCreateComboBoxField: 'FormCreateComboBoxField',
105105
formCreateListBoxField: 'FormCreateListBoxField',
106106
formFill: 'FormFill',
107+
annotationCreateCheckMarkStamp: 'AnnotationCreateCheckMarkStamp',
108+
annotationCreateCrossMarkStamp: 'AnnotationCreateCrossMarkStamp',
109+
annotationCreateDotStamp: 'AnnotationCreateDotStamp',
107110
insertPage: 'InsertPage',
108111
// iOS only.
109112
pencilKitDrawing: 'PencilKitDrawing',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-pdftron",
33
"title": "React Native Pdftron",
4-
"version": "3.0.3-30",
4+
"version": "3.0.3-31",
55
"description": "React Native Pdftron",
66
"main": "./lib/index.js",
77
"typings": "index.ts",

src/Config/Config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export const Config = {
107107
formCreateComboBoxField: 'FormCreateComboBoxField',
108108
formCreateListBoxField: 'FormCreateListBoxField',
109109
formFill: 'FormFill',
110+
annotationCreateCheckMarkStamp: 'AnnotationCreateCheckMarkStamp',
111+
annotationCreateCrossMarkStamp: 'AnnotationCreateCrossMarkStamp',
112+
annotationCreateDotStamp: 'AnnotationCreateDotStamp',
110113
insertPage: 'InsertPage',
111114

112115
// iOS only.

0 commit comments

Comments
 (0)