UIKit Android v3
UIKit Android
UIKit
Android
Home
/
UIKit
/
Android
This is the new Docs for UIKit v3 beta for Android. To see the previous Docs, click here.

Customize UIKitFragmentFactory

UIKitFragmentFactory is a class that provides and manages all fragments used in Sendbird UIKit. While an activity creates the basic UI screen and allows the user to navigate between different screens, the fragment within the activity is what allows you to customize components and manage data. The UIKitFragmentFactory class creates the fragment used in each activity.

If you wish to customize a fragment, you need to inherit the UIKitFragmentFactory class and override the method that creates the fragment. Then, you must return the customized fragment in order to apply the customization throughout the UIKit. Before creating the fragment, you need to also send data from the activity to the customized fragment through the Bundle class. The fragment will then use the data to build a view.

Note: If you're only using fragments to build a screen in UIKit instead of using an activity, you can skip the following steps.

  1. You need to first override the methods of the fragment you wish to customize by inheriting the UIKitFragmentFactory class. Refer to the code below as an example.
public class CustomFragmentFactory extends UIKitFragmentFactory {

    // TODO : Override the methods that create the fragment you wish to customize.

    @Override
    public Fragment newChannelFragment(@NonNull String channelUrl, @NonNull Bundle args) {
        // TODO : Return the customized `ChannelFragment` here.
        final CustomChannelFragment fragment = new CustomChannelFragment();
        // You can send data from activity to the custom fragment through `Bundle`.
        args.putString("KEY_CHANNEL_URL", channelUrl);
        fragment.setArguments(args);
        return fragment;
    }
}
  1. Apply the customized UIKitFragmentFactory to Application using SendbirdUIKit.setUIKitFragmentFactory(UIKitFragmentFactory).
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        SendbirdUIKit.setUIKitFragmentFactory(new CustomFragmentFactory());
    }
}