Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pgreze/android-reactions
Facebook like reaction picker for Android
https://github.com/pgreze/android-reactions
android android-reactions facebook java kotlin
Last synced: 4 days ago
JSON representation
Facebook like reaction picker for Android
- Host: GitHub
- URL: https://github.com/pgreze/android-reactions
- Owner: pgreze
- License: apache-2.0
- Created: 2018-11-21T13:11:32.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-05T05:19:11.000Z (over 3 years ago)
- Last Synced: 2023-11-07T20:05:00.890Z (about 1 year ago)
- Topics: android, android-reactions, facebook, java, kotlin
- Language: Kotlin
- Homepage:
- Size: 438 KB
- Stars: 157
- Watchers: 6
- Forks: 45
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Android reactions [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Build Status](https://github.com/pgreze/android-reactions/workflows/Build/badge.svg)](https://github.com/pgreze/android-reactions/actions?query=workflow%3ABuild)
An open source and fully customizable implementation of the
[Facebook reactions](https://en.facebookbrand.com/assets/reactions) pattern.
⚠️ Disclaimer: this library is in a maintenance mode (I'm not using it anymore) and maybe lacks some features you may want (design UI libraries is hard).
Feel free to fork it and add your own features, and hopefully open a PR to give back to the community.Alternatives:
1. https://github.com/amrdeveloper/ReactButton# Installation [![central](https://maven-badges.herokuapp.com/maven-central/com.github.pgreze/android-reactions/badge.svg?style={style})](https://search.maven.org/artifact/com.github.pgreze/android-reactions)
```groovy
repositories {
mavenCentral()
}dependencies {
// Check the 🔝 maven central badge 🔝 for latest $version
implementation "com.github.pgreze:android-reactions:$version"
}
```# Usage [![](https://img.shields.io/badge/dokka-read-blue)](https://android-reactions.netlify.app/)
See [Java](sample/src/main/java/com/github/pgreze/reactions/sample/MainActivity.java)
or [Kotlin](sample/src/main/java/com/github/pgreze/reactions/sample/KotlinSamples.kt) samples.1. Popup creation:
Kotlin DSL:
```kotlin
val config = reactionConfig(context) {
reactions {
resId { R.drawable.ic_fb_like }
resId { R.drawable.ic_fb_love }
resId { R.drawable.ic_fb_laugh }
reaction { R.drawable.ic_fb_wow scale ImageView.ScaleType.FIT_XY }
reaction { R.drawable.ic_fb_sad scale ImageView.ScaleType.FIT_XY }
reaction { R.drawable.ic_fb_angry scale ImageView.ScaleType.FIT_XY }
}
}val popup = ReactionPopup(context, config) { position -> true.also {
// position = -1 if no selection
} }
```Java:
```java
ReactionsConfig config = new ReactionsConfigBuilder(context)
.withReactions(new int[]{
R.drawable.ic_fb_like,
R.drawable.ic_fb_love,
R.drawable.ic_fb_laugh,
R.drawable.ic_fb_wow,
R.drawable.ic_fb_sad,
R.drawable.ic_fb_angry
})
.build()ReactionPopup popup = new ReactionPopup(context, config, (position) -> {
return true; // true is closing popup, false is requesting a new selection
});
```2. Bind popup with a button/view:
```java
View reactionButton = findViewById(R.id.reaction_button);
reactionButton.setOnTouchListener(popup);
```Notice: if button is inside a scroll view, you need to temporarily disable it:
```kotlin
reactionButton.setOnTouchListener { v, event ->
// Avoid scroll view to consume events
scrollView.requestDisallowInterceptTouchEvent(true)
// Resolve reactions selection
popup.onTouch(v, event)
}
```3. Additional config:
Kotlin:
```kotlin
val popup = reactionPopup(this, ::onReactionSelected) {
// Reaction DSL
reactions(scaleType = ImageView.ScaleType.FIT_XY) {
resId { R.drawable.img1 }
drawable { Drawable(...) }
reaction { R.drawable.img3 scale ImageView.ScaleType.FIT_CENTER }
reaction { Drawable(...) scale ImageView.ScaleType.FIT_CENTER }
}
// Alternative with drawable resource id array
reactionsIds = intArrayOf(R.drawable.img1, R.drawable.img2, R.drawable.img3)// Optional popup style
popupGravity = PopupGravity.DEFAULT
popupMargin = resources.getDimensionPixelSize(R.dimen.horizontal_margin)
popupCornerRadius = TypedValue.applyDimension(COMPLEX_UNIT_DIP, cornerSizeInDp.toFloat(), resources.displayMetrics)
popupColor = Color.WHITE
popupAlphaValue = 230// Optional item style
reactionSize = resources.getDimensionPixelSize(R.dimen.item_size)
horizontalMargin = resources.getDimensionPixelSize(R.dimen.item_margin)
verticalMargin = resources.getDimensionPixelSize(R.dimen.item_margin)// Text provider
reactionTextProvider = { position -> "Item $position" }
reactionTexts = R.array.descriptions
// Text styles
textBackground = ColorDrawable(Color.TRANSPARENT)
textColor = Color.BLACK
textHorizontalPadding = resources.getDimension(R.dimen.text_padding)
textVerticalPadding = resources.getDimension(R.dimen.text_padding)
}
```Java:
```java
// With resources
.withReactions(new int[]{ R.drawable.ic_fb_like, R.drawable.ic_fb_love })
// With drawables
.withReactions(Arrays.asList(drawable1, drawable2))
// item size (default: 24dp)
.withReactionSize(getResources().getDimensionPixelSize(R.dimen.item_size))
// Horizontal margin (default: 8dp)
.withHorizontalReactionMargin(margin)
// Vertical margin (default: 8dp)
.withVerticalReactionMargin(margin / 2)
// Override popup gravity
.withPopupGravity(PopupGravity.PARENT_RIGHT)
// Margin between items (default: R.dimen.reactions_item_margin)
.withPopupMargin(margin)
// Popup corners radius (default: 90)
.withCornerRadius(getResources().getDimensionPixelSize(R.dimen.corner_radius))
// Change popup color (default: white)
.withPopupColor(Color.LTGRAY)
// Popup background alpha value between 0 (full transparent) and 255 (full opaque) (default: 230)
.withPopupAlphaValue(255)
// Item text provider / string array (default: no texts)
.withReactionTexts(position -> descriptions[position])
.withReactionTexts(R.array.descriptions)
// Text popup background (default: #44000000 circle)
.withTextBackground(new ColorDrawable(Color.TRANSPARENT))
// Text color (default: white)
.withTextColor(Color.BLACK)
// Text horizontal margin (default: 12dp)
.withTextHorizontalPadding(0)
// Text vertical margin (default: 4dp)
.withTextVerticalPadding(0)
// Text size (default: 8sp)
.withTextSize(getResources().getDimension(R.dimen.text_size))
```# Credits
- [Hardyk/FbReactionDemo](https://github.com/Hardyk/FbReactionDemo)
- [coinranking/cryptocurrency-icons](https://github.com/coinranking/cryptocurrency-icons)
- [LICEcap](https://www.cockos.com/licecap/)