Back to Android Oss

Social Share

app/src/main/java/com/kickstarter/features/socialshare/README.md

3.40.03.5 KB
Original Source

Social Share

Overview

The Social Share feature lets users share a Kickstarter project with their network directly from within the app. When a user taps the share button on a project a bottom sheet slides up presenting a grid of sharing destinations alongside a preview card of the project.

Supported platforms

IconDestinationRequires app installed?
XX (Twitter)Yes
InstagramInstagram FeedYes
InstagramInstagram StoriesYes
FacebookFacebook FeedYes
FacebookFacebook StoriesYes
WhatsAppWhatsAppYes
MessagesSMS / iMessageNo (native)
EmailEmailNo (native)
MoreNative system share sheetNo (native)
Copy LinkClipboardNo

Architecture

The feature is structured as a self-contained package under features/socialshare/:

  • SocialShareService / AndroidSocialShareService — interface that abstracts all Android framework calls (PackageManager, ClipboardManager, FileProvider, intent construction) so the ViewModel never holds a Context.
  • SocialShareViewModel — on creation it detects which platform apps are installed and begins caching the project image in the background. Exposes onPlatformSelected, onCopyLinkClicked, and onCopiedToastShown.
  • SocialShareSheet — a ModalBottomSheet composable. It reads the ViewModel through LocalSocialShareViewModel (a CompositionLocalProvider) so the ViewModel is always created by the caller with the correct shareData rather than inside the composable itself.
  • ShareImageCache — downloads the project image and writes it to the app cache as a content:// URI via FileProvider, which is required to grant read permission to third-party apps.
  • SocialShareIntentBuilder — constructs the correct Intent per platform.

How to integrate

Create the ViewModel where you have access to shareData, then wrap the sheet in a CompositionLocalProvider:

kotlin
shareData?.let { data ->
    val shareViewModel = remember(data) {
        SocialShareViewModel(
            shareService = AndroidSocialShareService(context.applicationContext),
            shareData = data
        )
    }
    CompositionLocalProvider(LocalSocialShareViewModel provides shareViewModel) {
        SocialShareSheet(
            shareData = data,
            isVisible = true,
            onDismiss = { shareData = null },
            onIntentReady = { startActivity(it) }
        )
    }
}

Intent Content Summary

This section summarizes the content included in the intents generated by SocialShareIntentBuilder for each platform.

PlatformIncludes Image?Includes Link?Includes Text (Name)?Notes
X (Twitter)Supports both image and text/link via ACTION_SEND.
WhatsAppText is rendered as a caption beneath the image.
Messages (SMS)Text-only via ACTION_SENDTO for reliability across OEMs.
EmailImage as inline attachment; falls back to mailto: if no image.
Instagram FeedUses EXTRA_TEXT; behavior depends on Instagram app version.
Facebook FeedUses EXTRA_TEXT; behavior depends on Facebook app version.
Native ChooserUniversal fallback for any app not listed explicitly.
Stories (IG/FB)Custom ADD_TO_STORY actions do not have a text/link slot.