|
20 | 20 | import androidx.appcompat.app.AppCompatActivity; |
21 | 21 | import androidx.fragment.app.Fragment; |
22 | 22 | import androidx.fragment.app.FragmentManager; |
| 23 | +import androidx.lifecycle.Lifecycle; |
23 | 24 |
|
24 | 25 | import com.facebook.react.bridge.Arguments; |
25 | 26 | import com.facebook.react.bridge.Promise; |
@@ -2218,7 +2219,41 @@ public void requestLayout() { |
2218 | 2219 |
|
2219 | 2220 | @Override |
2220 | 2221 | protected void prepView() { |
2221 | | - super.prepView(); |
| 2222 | + // Create a viewer builder with the specified parameters |
| 2223 | + buildViewer(); |
| 2224 | + if (mViewerBuilder == null) { |
| 2225 | + return; |
| 2226 | + } |
| 2227 | + |
| 2228 | + Context context = getContext(); |
| 2229 | + Activity activity = null; |
| 2230 | + if (context instanceof ThemedReactContext) { |
| 2231 | + activity = ((ThemedReactContext) context).getCurrentActivity(); |
| 2232 | + } |
| 2233 | + if (activity instanceof AppCompatActivity) { |
| 2234 | + if (activity.isFinishing() || !((AppCompatActivity) activity).getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { |
| 2235 | + return; |
| 2236 | + } |
| 2237 | + } |
| 2238 | + |
| 2239 | + if (mPdfViewCtrlTabHostFragment != null) { |
| 2240 | + mPdfViewCtrlTabHostFragment.onOpenAddNewTab(mViewerBuilder.createBundle(getContext())); |
| 2241 | + } else { |
| 2242 | + mPdfViewCtrlTabHostFragment = getViewer(); |
| 2243 | + mPdfViewCtrlTabHostFragment.addHostListener(this); |
| 2244 | + |
| 2245 | + if (mFragmentManager != null) { |
| 2246 | + mFragmentManager.beginTransaction() |
| 2247 | + .add(mPdfViewCtrlTabHostFragment, String.valueOf(getId())) |
| 2248 | + .commitNowAllowingStateLoss(); |
| 2249 | + |
| 2250 | + View fragmentView = mPdfViewCtrlTabHostFragment.getView(); |
| 2251 | + if (fragmentView != null) { |
| 2252 | + fragmentView.clearFocus(); // work around issue where somehow new ui obtains focus |
| 2253 | + addView(fragmentView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); |
| 2254 | + } |
| 2255 | + } |
| 2256 | + } |
2222 | 2257 |
|
2223 | 2258 | if (mPdfViewCtrlTabHostFragment != null && mPdfViewCtrlTabHostFragment.getView() == null) { |
2224 | 2259 | if (mPdfViewCtrlTabHostFragment instanceof RNPdfViewCtrlTabHostFragment) { |
@@ -3105,6 +3140,10 @@ public void onTabDocumentLoaded(String tag) { |
3105 | 3140 | fragment.setReactContext((ReactContext) getContext(), getId()); |
3106 | 3141 | } |
3107 | 3142 |
|
| 3143 | + if (getPdfViewCtrl() == null || getToolManager() == null) { |
| 3144 | + return; |
| 3145 | + } |
| 3146 | + |
3108 | 3147 | // Hide add page annotation toolbar button |
3109 | 3148 | if (!mShowAddPageToolbarButton) { |
3110 | 3149 | mPdfViewCtrlTabHostFragment.toolbarButtonVisibility(ToolbarButtonType.ADD_PAGE, false); |
|
0 commit comments