Onboarding Android Library

repository·master·Indexed 23 days ago

https://github.com/eoinfogarty/onboarding

An Android library for creating visually engaging user introduction flows using a ViewPager and custom transformers. It provides the BaseSceneFragment class and SceneChangeListener interface to manage scene transitions and UI states as users navigate through onboarding pages.

Tokens
824
Snippets
2
Records
3
Agent score
31%

What's inside Onboarding

  1. Overview of Onboarding

    master
    Onboarding is an Android library designed to provide a beautiful way to introduce users to an app. It achieves its visual effects by using a regular ViewPager combined with a custom transformer that utilizes callbacks to manage scene transitions.
  2. Implement SceneChangeListener to react to movement

    master

    To create custom onboarding transitions, you must implement the SceneChangeListener interface. This interface provides callbacks that allow you to react as a scene enters, centers, or exits the viewport, or when it is no longer in view. This is typically implemented within a Fragment to manage the UI state of each onboarding page.

    public interface SceneChangeListener {
    
        void enterScene(@Nullable ImageView sharedElement, float position);
    
        void centerScene(@Nullable ImageView sharedElement);
    
        void exitScene(@Nullable ImageView sharedElement, float position);
    
        void notInScene();
    }
  3. Extend BaseSceneFragment for onboarding scenes

    master

    The library provides BaseSceneFragment, an abstract class that implements SceneTransformer.SceneChangeListener. To use it, extend this class and override the lifecycle methods (enterScene, centerScene, exitScene, and notInScene).

    Important: You must set a position tag on the root layout of every scene fragment so the transformer can identify which fragment to trigger callbacks for. Use the setRootPositionTag(@NonNull View root) method provided by the base class to do this.

    public abstract class BaseSceneFragment extends Fragment
            implements SceneTransformer.SceneChangeListener {
    
        protected static final String KEY_POSITION = "KEY_POSITION";
    
        // we have to set a position tag to the root layout of every scene fragment
        // this is so the transformer will know who to make a callback to
        protected void setRootPositionTag(@NonNull View root) {
            root.setTag(getArguments().getInt(KEY_POSITION));
        }
    
        @Override
        public abstract void enterScene(@Nullable ImageView sharedElement, float position);
    
        @Override
        public abstract void centerScene(@Nullable ImageView sharedElement);
    
        @Override
        public abstract void exitScene(@Nullable ImageView sharedElement, float position);
    
        @Override
        public abstract void notInScene();
    
        ... 
    }