# Custom Story Group Styling
WARNING
This section is valid if you are using Storyly SDK version 1.16.0 or higher.
This guide shows you how to customize the story group view's style. Storyly provides three different pre-defined story group styles; Small
, Large
and Custom
. However, if you want to use different style other than these pre-defined ones or if pre-defined ones do not satisfy your expectations then you should follow this section.
WARNING
If you are using pre-defined sizes and want to apply only some customizations, follow UI Customizations section.
# Story Group View Factory
You need to set storyGroupViewFactory
field of StorylyView
as a start point of the setup. You need to create a class that is subclass of StoryGroupViewFactory
and implement createView
function.
// Assume we have a StorylyView instance called storylyView
storylyView.storyGroupViewFactory = SampleViewFactory(context)
class SampleViewFactory(val context: Context): StoryGroupViewFactory() {
override fun createView(): StoryGroupView {
return SampleView(context)
}
}
StoryGroupViewFactory
calls createView
function whenever a new view is required. It will request an instance of your view for each of the story groups while creating the StorylyView
. Therefore, each story group is associated with different instances of your view. Note that, Storyly SDK uses RecyclerView to show lists so that a new view is not required for each time, recycled views will be used.
# Story Group View
StoryGroupView
class is used to represent the view that will be shown as a single story group. In order to use your own custom view, your view should be subclass of StoryGroupView
class and implement its functions;
class SampleView(context: Context) : StoryGroupView(context) {
private val sampleViewBinding: SampleViewBinding = SampleViewBinding.inflate(LayoutInflater.from(context))
init {
addView(sampleViewBinding.root)
layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
}
override fun populateView(storyGroup: StoryGroup?) {
// Handle populating view with Storyly related data
// ie, sampleViewBinding.sampleText.text = storyGroup?.title
}
}
populateView
function is called when your view is about to be shown. Its storyGroup
parameter has all of the information that you provided in Storyly dashboard for your story groups. You can find the details of the StoryGroup
below:
data class StoryGroup(
val id: Int,
val title: String,
val iconUrl: String,
val thematicIconUrls: Map<String, String>?,
val coverUrl: String?,
val index: Int,
val seen: Boolean,
val stories: List<Story>,
val pinned: Boolean,
val type: StoryGroupType
)
TIP
You can find the explanation of each field from the API Reference (opens new window) section.
TIP
Please check the this github (opens new window) page for implemented samples.
Warning Additional data
Do not forget to use additional fields of the storyGroup
parameter of the populateView
function. For instance, if you want to show pinned groups, you can use pinned
field of the object or if you want to show IVOD(Interactive VideOnDemand) groups, you can use the type
field of the object.
# Summary
To sum up, in order to use your own custom group style, you need to follow the steps below:
- Create your own custom style in XML or programmatically.
- Use this style in a class that is subclass of
StoryGroupView
by inflating the XML and adding its view or by adding views programmatically. - Override
populateView
function in the previous class you defined and by using the data instoryGroup
parameter, fill your UI components. - Create a subclass of
StoryGroupViewFactory
in order to serve as your factory. - Override
createView
function in the previous class you defined and return a new instance of yourStoryGroupView
subclass. - Create a new instance of
StoryGroupViewFactory
subclass and setstoryGroupViewFactory
variable of the StorylyView with this instance.