-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b21d72
commit 7308e37
Showing
21 changed files
with
250 additions
and
317 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.pictures"> | ||
|
||
<application> | ||
<activity android:name=".PictureViewerActivity" /> | ||
</application> | ||
package="com.pictures"> | ||
</manifest> |
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 |
---|---|---|
@@ -1,7 +1,2 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.pictures"> | ||
|
||
<application> | ||
<activity android:name=".PictureViewerActivity" /> | ||
</application> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
</manifest> |
81 changes: 0 additions & 81 deletions
81
android/src/main/java/com/pictures/PictureViewerActivity.kt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.pictures | ||
|
||
import android.view.View | ||
import com.facebook.react.uimanager.SimpleViewManager | ||
import com.facebook.react.uimanager.ThemedReactContext | ||
import com.facebook.react.uimanager.annotations.ReactProp | ||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import android.widget.FrameLayout | ||
import com.github.chrisbanes.photoview.PhotoView | ||
import java.net.HttpURLConnection | ||
import java.net.URL | ||
|
||
class PicturesViewManager : SimpleViewManager<PicturesView>() { | ||
override fun getName() = "PicturesView" | ||
|
||
override fun createViewInstance(reactContext: ThemedReactContext): PicturesView { | ||
return PicturesView(reactContext) | ||
} | ||
|
||
@ReactProp(name = "imageUrl") | ||
fun setImageUrl(view: PicturesView, imageUrl: String) { | ||
view.loadImage(imageUrl) | ||
} | ||
|
||
} | ||
|
||
class PicturesView(context: Context) : FrameLayout(context) { | ||
|
||
private val imageView: PhotoView = PhotoView(context).apply { | ||
layoutParams = LayoutParams( | ||
LayoutParams.MATCH_PARENT, | ||
LayoutParams.MATCH_PARENT | ||
) | ||
} | ||
|
||
init { | ||
addView(imageView) | ||
} | ||
|
||
fun loadImage(imageUrl: String) { | ||
// Load the image similarly as in your activity | ||
Thread { | ||
try { | ||
val url = URL(imageUrl) | ||
val connection = url.openConnection() as HttpURLConnection | ||
connection.doInput = true | ||
connection.connect() | ||
val inputStream = connection.inputStream | ||
val originalBitmap = BitmapFactory.decodeStream(inputStream) | ||
|
||
// Resize the bitmap to avoid Bitmap being too big and causing a crash | ||
val aspectRatio = originalBitmap.width.toFloat() / originalBitmap.height.toFloat() | ||
val targetWidth = imageView.width // You might want to adjust this | ||
val targetHeight = (targetWidth / aspectRatio).toInt() | ||
|
||
val resizedBitmap = | ||
Bitmap.createScaledBitmap(originalBitmap, targetWidth, targetHeight, false) | ||
|
||
|
||
post { | ||
imageView.setImageBitmap(resizedBitmap) | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
// Handle exceptions | ||
} | ||
}.start() | ||
} | ||
} | ||
|
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
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
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
#import <React/RCTBridgeModule.h> | ||
#import <React/RCTViewManager.h> |
Oops, something went wrong.