MaterialShowcaseView icon indicating copy to clipboard operation
MaterialShowcaseView copied to clipboard

Dismiss the Showcase on Back button press when inside a Fragment

Open masudias opened this issue 8 years ago • 5 comments

I tried to implement the ShowcaseView inside a Fragment. The problem I noticed is that when I press the back button the ShowcaseView doesn't disappear. So the problem arises that, the previous fragment is loaded and the ShowcaseView is pointing to a random UI element.

masudias avatar May 03 '16 16:05 masudias

same problem here

waniolka avatar Sep 16 '16 07:09 waniolka

Hi, I resolved this problem adding a list of MaterialShowcaseViews in a base fragment class when I create the sequence items, and overriding the onbackpress on the activity to remove all views in this list off the screen:

for (MaterialShowcaseView item : mHelpViews) {
      item.removeFromWindow();
}

You just need to consider that removing the view will call the dismiss listener, if you have one for any MaterialShowcaseView.

shipjacker avatar Dec 20 '16 14:12 shipjacker

@shipjacker Can't we do just item.hide() in this case?

yashasvigirdhar avatar Jan 31 '17 15:01 yashasvigirdhar

I did the same as @shipjacker . First, I use a global variable and whenever I create a MaterialShowCaseView assignit there. Then I Just override the onPause method of the fragment to hide the golbalMaterialShowCase if it's not null and is showing.

chnt-gomez avatar Mar 30 '17 16:03 chnt-gomez

removeFromWindow works for showcaseview, but not for sequence, since the items are in a private queue, and not accessible. So i inherited it, and manually add items to a list. the remove() method is called when the onPause event is fired from my fragment so that it doesn't point at random UI elements

public class myMaterialSequence extends MaterialShowcaseSequence {
    private ArrayList<MaterialShowcaseView> sequenceItems;
    Activity activity;

    public myMaterialSequence(Activity activity, String ID) {
        super(activity,ID);
        sequenceItems=new ArrayList<>();
        this.activity = activity;
        ShowcaseConfig config = new ShowcaseConfig();
        config.setDelay(200); // delay between each showcase view
        config.setFadeDuration(300);
    }

    public void addItem(View target, String title, String desc, String dismissText){
        MaterialShowcaseView sequenceItem = new MaterialShowcaseView.Builder(activity)
                .setTarget(target)
                .setTitleText(title)
                .setDismissText(dismissText)
                .setContentText(desc)
                .setSequence(true)
                .build();
        this.addSequenceItem(sequenceItem);
        sequenceItems.add(sequenceItem);
    }

    public void remove(){
        for (MaterialShowcaseView item : sequenceItems) {
            Log.e("SEQUENCE","Remove"+item.getId()+","+item.getTransitionName());
            item.removeFromWindow();
        }
    }

}

jithinbp avatar May 15 '23 08:05 jithinbp