Skip to content

Commit

Permalink
fix(android): app crashing on selection of gif
Browse files Browse the repository at this point in the history
fix #90
  • Loading branch information
pshoniuk committed Mar 2, 2023
1 parent 213d823 commit 2c13057
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import timber.log.Timber
import java.io.IOException

const val VIDEO_PLAYER_ADAPTER_STUB_IMPL = false

class VideoPlayerAdapterImpl(
playerView: GPHVideoPlayerView?,
repeatable: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,3 @@ abstract class AbstractVideoPlayerAdapter(
abstract fun runInPlayerApplicationLooper(runnable: Runnable)
}

abstract class AbstractFakeVideoPlayerAdapter(
playerView: GPHVideoPlayerView?,
repeatable: Boolean,
showCaptions: Boolean
) : AbstractVideoPlayerAdapter(playerView, repeatable, showCaptions)
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package com.giphyreactnativesdk.videoplayeradapter
import android.view.SurfaceView
import com.giphy.sdk.ui.views.GPHVideoPlayerView

const val VIDEO_PLAYER_ADAPTER_STUB_IMPL = true

class VideoPlayerAdapterImpl(
playerView: GPHVideoPlayerView?,
repeatable: Boolean = false,
showCaptions: Boolean = true
) : AbstractFakeVideoPlayerAdapter(playerView, repeatable, showCaptions) {
) : AbstractVideoPlayerAdapter(playerView, repeatable, showCaptions) {
override fun runInPlayerApplicationLooper(runnable: Runnable) {
}

Expand Down
16 changes: 2 additions & 14 deletions android/src/main/java/com/giphyreactnativesdk/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,17 @@ package com.giphyreactnativesdk

import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.WritableMap
import com.giphy.sdk.core.models.Image
import com.giphy.sdk.core.models.Media
import com.giphy.sdk.core.models.enums.MediaType
import com.giphy.sdk.core.models.enums.RenditionType
import com.giphy.sdk.ui.utils.GifUtils
import com.giphy.sdk.ui.utils.aspectRatio
import com.giphyreactnativesdk.utils.jsonObjectToRNMap
import com.google.gson.Gson
import kotlin.reflect.KProperty1

@Suppress("UNCHECKED_CAST")
fun <R> readInstanceProperty(instance: Any, propertyName: String): R {
val property = instance::class.members
// don't cast here to <Any, R>, it would succeed silently
.first { it.name == propertyName } as KProperty1<Any, *>
// force a invalid cast exception if incorrect type here
return property.get(instance) as R
}

fun getGifURL(media: Media, renditionType: RenditionType?): String? {
val rendition = renditionType ?: RenditionType.downsized
val image = readInstanceProperty<Image>(media.images, rendition.name) ?:
readInstanceProperty<Image>(media.images, RenditionType.original.name)
return image?.gifUrl
return GifUtils.getImageDataForType(media, rendition)?.gifUrl
}

fun mediaToRNMap(media: Media, renditionType: RenditionType?): WritableMap {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.giphyreactnativesdk.utils

import com.giphy.sdk.ui.views.GPHVideoPlayerView
import com.giphyreactnativesdk.videoplayeradapter.AbstractFakeVideoPlayerAdapter
import com.giphyreactnativesdk.videoplayeradapter.VIDEO_PLAYER_ADAPTER_STUB_IMPL
import com.giphyreactnativesdk.videoplayeradapter.VideoPlayerAdapterImpl
import kotlin.reflect.full.isSubclassOf

fun getVideoPlayerFactory(): ((GPHVideoPlayerView?, Boolean, Boolean) -> VideoPlayerAdapterImpl)? {
if (VideoPlayerAdapterImpl::class.isSubclassOf(AbstractFakeVideoPlayerAdapter::class)) {
if (VIDEO_PLAYER_ADAPTER_STUB_IMPL) {
return null
}

Expand Down
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
def enableProguardInReleaseBuilds = true

/**
* The preferred build flavor of JavaScriptCore.
Expand Down Expand Up @@ -162,7 +162,7 @@ android {
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
proguardFile "${rootProject.projectDir}/../../node_modules/detox/android/detox/proguard-rules-app.pro"
}
}
// applicationVariants are e.g. debug, release
Expand Down
3 changes: 3 additions & 0 deletions example/android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:
-keep class com.facebook.react.views.** { *; }
-keep class androidx.appcompat.widget.** { *; }
-keep class com.reactnativecommunity.picker.** { *; }

0 comments on commit 2c13057

Please sign in to comment.