@@ -11,7 +11,7 @@ With [Material Design Bottom Navigation pattern](https://www.google.com/design/s
1111## Gradle
1212
1313``` groovy
14- implementation 'com.ncapdevi:frag-nav:2.3 .0' //or or `compile` if on older gradle version
14+ implementation 'com.ncapdevi:frag-nav:2.4 .0' //or or `compile` if on older gradle version
1515```
1616
1717## How do I implement it?
@@ -161,16 +161,16 @@ Use FragNavController.setTransitionMode();
161161
162162### Helper functions
163163```java
164-
165- /**
164+ /**
166165 * Get the number of fragment stacks
167166 *
168167 * @return the number of fragment stacks
169168 */
170169 @CheckResult
171- public int getSize()
172-
173-
170+ public int getSize() {
171+ return mFragmentStacks.size();
172+ }
173+
174174 /**
175175 * Get a copy of the stack at a given index
176176 *
@@ -179,42 +179,73 @@ Use FragNavController.setTransitionMode();
179179 @SuppressWarnings("unchecked")
180180 @CheckResult
181181 @Nullable
182- public Stack<Fragment> getStack(@TabIndex int index)
183-
184- /**
185- * Get a copy of the current stack that is being displayed
186- *
187- * @return Current stack
188- */
189- @SuppressWarnings("unchecked")
190- @CheckResult
191- @Nullable
192- public Stack<Fragment> getCurrentStack()
193-
194- /**
195- * Get the index of the current stack that is being displayed
196- *
197- * @return Current stack index
198- */
199- @CheckResult
200- @TabIndex
201- public int getCurrentStackIndex()
202-
203-
182+ public Stack<Fragment> getStack(@TabIndex int index) {
183+ if (index == NO_TAB) {
184+ return null;
185+ }
186+ if (index >= mFragmentStacks.size()) {
187+ throw new IndexOutOfBoundsException("Can' t get an index that' s larger than we' ve setup");
188+ }
189+ return (Stack<Fragment > ) mFragmentStacks. get(index). clone();
190+ }
191+
192+ /**
193+ * Get a copy of the current stack that is being displayed
194+ *
195+ * @return Current stack
196+ */
197+ @SuppressWarnings (" unchecked" )
198+ @CheckResult
199+ @Nullable
200+ public Stack<Fragment > getCurrentStack() {
201+ return getStack(mSelectedTabIndex);
202+ }
203+
204+ /**
205+ * Get the index of the current stack that is being displayed
206+ *
207+ * @return Current stack index
208+ */
209+ @CheckResult
210+ @TabIndex
211+ public int getCurrentStackIndex() {
212+ return mSelectedTabIndex;
213+ }
214+
204215 /**
205216 * @return If true, you are at the bottom of the stack
206217 * (Consider using replaceFragment if you need to change the root fragment for some reason)
207218 * else you can popFragment as needed as your are not at the root
208219 */
209220 @CheckResult
210- public boolean isRootFragment()
211-
212- /**
213- * @return Current DialogFragment being displayed. Null if none
214- */
215- @Nullable
216- @CheckResult
217- public DialogFragment getCurrentDialogFrag()
221+ public boolean isRootFragment() {
222+ Stack<Fragment > stack = getCurrentStack();
223+
224+ return stack == null || stack. size() == 1 ;
225+ }
226+
227+ /**
228+ * Helper function to get wether the fragmentManger has gone through a stateSave, if this is true, you probably want to commit allowing stateloss
229+ *
230+ * @return if fragmentManger isStateSaved
231+ */
232+ public boolean isStateSaved() {
233+ return mFragmentManager. isStateSaved();
234+ }
235+
236+ /**
237+ * Use this if you need to make sure that pending transactions occur immediately. This call is safe to
238+ * call as often as you want as there's a check to prevent multiple executePendingTransactions at once
239+ *
240+ */
241+ public void executePendingTransactions() {
242+ if (! mExecutingTransaction) {
243+ mExecutingTransaction = true ;
244+ mFragmentManager. executePendingTransactions();
245+ mExecutingTransaction = false ;
246+ }
247+ }
248+
218249
219250```
220251## Apps Using FragNav
0 commit comments