|
27 | 27 | import com.pspdfkit.forms.ComboBoxFormElement;
|
28 | 28 | import com.pspdfkit.forms.EditableButtonFormElement;
|
29 | 29 | import com.pspdfkit.forms.TextFormElement;
|
| 30 | +import com.pspdfkit.listeners.OnVisibilityChangedListener; |
30 | 31 | import com.pspdfkit.listeners.SimpleDocumentListener;
|
31 | 32 | import com.pspdfkit.react.events.PdfViewAnnotationChangedEvent;
|
32 | 33 | import com.pspdfkit.react.events.PdfViewAnnotationTappedEvent;
|
|
41 | 42 | import com.pspdfkit.ui.PdfFragment;
|
42 | 43 | import com.pspdfkit.ui.PdfUiFragment;
|
43 | 44 | import com.pspdfkit.ui.PdfUiFragmentBuilder;
|
| 45 | +import com.pspdfkit.ui.search.PdfSearchView; |
| 46 | +import com.pspdfkit.ui.search.PdfSearchViewInline; |
44 | 47 | import com.pspdfkit.ui.toolbar.grouping.MenuItemGroupingRule;
|
45 | 48 |
|
46 | 49 | import org.json.JSONArray;
|
@@ -106,6 +109,11 @@ public class PdfView extends FrameLayout {
|
106 | 109 | /** An internal id we generate so we can track if fragments found belong to this specific PdfView instance. */
|
107 | 110 | private int internalId;
|
108 | 111 |
|
| 112 | + /** We keep track if the navigation button should be shown so we can show it when the inline search view is closed. */ |
| 113 | + private boolean isNavigationButtonShown = false; |
| 114 | + /** We keep track if the inline search view is shown since we don't want to add a second navigation button while it is shown. */ |
| 115 | + private boolean isSearchViewShown = false; |
| 116 | + |
109 | 117 | public PdfView(@NonNull Context context) {
|
110 | 118 | super(context);
|
111 | 119 | init();
|
@@ -224,10 +232,13 @@ public void setMenuItemGroupingRule(@NonNull MenuItemGroupingRule groupingRule)
|
224 | 232 | }
|
225 | 233 |
|
226 | 234 | public void setShowNavigationButtonInToolbar(final boolean showNavigationButtonInToolbar) {
|
| 235 | + isNavigationButtonShown = showNavigationButtonInToolbar; |
227 | 236 | pendingFragmentActions.add(getCurrentPdfUiFragment()
|
228 | 237 | .observeOn(Schedulers.io())
|
229 | 238 | .subscribe(pdfUiFragment -> {
|
230 |
| - ((ReactPdfUiFragment) pdfUiFragment).setShowNavigationButtonInToolbar(showNavigationButtonInToolbar); |
| 239 | + if (!isSearchViewShown) { |
| 240 | + ((ReactPdfUiFragment) pdfUiFragment).setShowNavigationButtonInToolbar(showNavigationButtonInToolbar); |
| 241 | + } |
231 | 242 | }));
|
232 | 243 | }
|
233 | 244 |
|
@@ -304,6 +315,22 @@ public void onNavigationButtonClicked(@NonNull PdfUiFragment pdfUiFragment) {
|
304 | 315 | }
|
305 | 316 | });
|
306 | 317 |
|
| 318 | + PdfSearchView searchView = pdfUiFragment.getPSPDFKitViews().getSearchView(); |
| 319 | + if (searchView instanceof PdfSearchViewInline) { |
| 320 | + // The inline search view provides its own back button hide ours if it becomes visible. |
| 321 | + searchView.addOnVisibilityChangedListener(new OnVisibilityChangedListener() { |
| 322 | + @Override |
| 323 | + public void onShow(@NonNull View view) { |
| 324 | + ((ReactPdfUiFragment) pdfUiFragment).setShowNavigationButtonInToolbar(false); |
| 325 | + } |
| 326 | + |
| 327 | + @Override |
| 328 | + public void onHide(@NonNull View view) { |
| 329 | + ((ReactPdfUiFragment) pdfUiFragment).setShowNavigationButtonInToolbar(isNavigationButtonShown); |
| 330 | + } |
| 331 | + }); |
| 332 | + } |
| 333 | + |
307 | 334 | // After attaching the PdfUiFragment we can access the PdfFragment.
|
308 | 335 | preparePdfFragment(pdfUiFragment.getPdfFragment());
|
309 | 336 | }
|
|
0 commit comments