-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: svg support * define modular headers * add examples, make loading async on Android * fix: iOS scaling * add: remote URL example * docs: instruct users to use_frameworks!
- Loading branch information
1 parent
28ce672
commit 1b0ed94
Showing
24 changed files
with
462 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
android/src/main/java/com/rcttabview/TabViewAppGlideModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.rcttabview | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import com.bumptech.glide.GlideBuilder | ||
import com.bumptech.glide.annotation.GlideModule | ||
import com.bumptech.glide.module.AppGlideModule | ||
|
||
@GlideModule | ||
class TabViewAppGlideModule : AppGlideModule() { | ||
override fun applyOptions(context: Context, builder: GlideBuilder) { | ||
super.applyOptions(context, builder) | ||
|
||
builder.setLogLevel( | ||
Log.ERROR | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.rcttabview.svg | ||
|
||
import com.bumptech.glide.load.Options | ||
import com.bumptech.glide.load.ResourceDecoder | ||
import com.bumptech.glide.load.engine.Resource | ||
import com.bumptech.glide.load.resource.SimpleResource | ||
import com.caverock.androidsvg.SVG | ||
import com.caverock.androidsvg.SVGParseException | ||
import java.io.IOException | ||
import java.io.InputStream | ||
|
||
|
||
class SVGDecoder : ResourceDecoder<InputStream, SVG> { | ||
override fun handles(source: InputStream, options: Options) = true | ||
|
||
companion object { | ||
const val DEFAULT_SIZE = 40f | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun decode(source: InputStream, width: Int, height: Int, options: Options): Resource<SVG>? { | ||
return try { | ||
val svg: SVG = SVG.getFromInputStream(source) | ||
// Taken from https://github.com/expo/expo/blob/215d8a13a7ef3f0b36b14eead41291e2d2d6cd0c/packages/expo-image/android/src/main/java/expo/modules/image/svg/SVGDecoder.kt#L28 | ||
if (svg.documentViewBox == null) { | ||
val documentWidth = svg.documentWidth | ||
val documentHeight = svg.documentHeight | ||
if (documentWidth != -1f && documentHeight != -1f) { | ||
svg.setDocumentViewBox(0f, 0f, documentWidth, documentHeight) | ||
} | ||
} | ||
|
||
svg.documentWidth = DEFAULT_SIZE | ||
svg.documentHeight = DEFAULT_SIZE | ||
SimpleResource(svg) | ||
} catch (ex: SVGParseException) { | ||
throw IOException("Cannot load SVG from stream", ex) | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
android/src/main/java/com/rcttabview/svg/SVGDrawableTranscoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.rcttabview.svg | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.Canvas | ||
import android.graphics.drawable.BitmapDrawable | ||
import android.graphics.drawable.Drawable | ||
import android.graphics.drawable.PictureDrawable | ||
import com.bumptech.glide.load.Options | ||
import com.bumptech.glide.load.engine.Resource | ||
import com.bumptech.glide.load.resource.SimpleResource | ||
import com.bumptech.glide.load.resource.transcode.ResourceTranscoder | ||
import com.caverock.androidsvg.SVG | ||
|
||
class SVGDrawableTranscoder(val context: Context) : ResourceTranscoder<SVG?, Drawable> { | ||
override fun transcode(toTranscode: Resource<SVG?>, options: Options): Resource<Drawable> { | ||
val svg = toTranscode.get() | ||
val picture = svg.renderToPicture() | ||
val drawable = PictureDrawable(picture) | ||
|
||
val returnedBitmap = Bitmap.createBitmap( | ||
drawable.intrinsicWidth, | ||
drawable.intrinsicHeight, | ||
Bitmap.Config.ARGB_8888 | ||
) | ||
|
||
val canvas = Canvas(returnedBitmap) | ||
canvas.drawPicture(drawable.picture) | ||
val bitMapDrawable = BitmapDrawable(context.resources, returnedBitmap) | ||
return SimpleResource(bitMapDrawable) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
android/src/main/java/com/rcttabview/svg/TabViewGlideModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.rcttabview.svg | ||
|
||
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import com.bumptech.glide.Glide | ||
import com.bumptech.glide.Registry | ||
import com.bumptech.glide.annotation.GlideModule | ||
import com.bumptech.glide.module.LibraryGlideModule | ||
import com.caverock.androidsvg.SVG | ||
import java.io.InputStream | ||
|
||
|
||
@GlideModule | ||
class SvgModule: LibraryGlideModule() { | ||
override fun registerComponents( | ||
context: Context, glide: Glide, registry: Registry | ||
) { | ||
registry | ||
.register( | ||
SVG::class.java, | ||
Drawable::class.java, SVGDrawableTranscoder(context) | ||
) | ||
.append(InputStream::class.java, SVG::class.java, SVGDecoder()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.