Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
react-native-fast-image
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
react-native-fast-image
Commits
8f702ed1
Commit
8f702ed1
authored
Aug 27, 2018
by
Patrick Kempff
Committed by
Dylan Vann
Oct 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed crash where activity was already destroyed before react-native could cleanup view manager
parent
1443a1a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
13 deletions
+66
-13
android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java
...in/java/com/dylanvann/fastimage/FastImageViewManager.java
+66
-13
No files found.
android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java
View file @
8f702ed1
package
com.dylanvann.fastimage
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.os.Build
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.RequestManager
;
import
com.bumptech.glide.load.model.GlideUrl
;
...
...
@@ -30,6 +34,8 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
private
static
final
String
REACT_ON_LOAD_START_EVENT
=
"onFastImageLoadStart"
;
private
static
final
String
REACT_ON_PROGRESS_EVENT
=
"onFastImageProgress"
;
private
static
final
Map
<
String
,
List
<
FastImageViewWithUrl
>>
VIEWS_FOR_URLS
=
new
WeakHashMap
<>();
@Nullable
private
RequestManager
requestManager
=
null
;
@Override
...
...
@@ -39,7 +45,10 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
@Override
protected
FastImageViewWithUrl
createViewInstance
(
ThemedReactContext
reactContext
)
{
requestManager
=
Glide
.
with
(
reactContext
);
if
(
isValidContextForGlide
(
reactContext
))
{
requestManager
=
Glide
.
with
(
reactContext
);
}
return
new
FastImageViewWithUrl
(
reactContext
);
}
...
...
@@ -47,7 +56,10 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
public
void
setSrc
(
FastImageViewWithUrl
view
,
@Nullable
ReadableMap
source
)
{
if
(
source
==
null
)
{
// Cancel existing requests.
requestManager
.
clear
(
view
);
if
(
requestManager
!=
null
)
{
requestManager
.
clear
(
view
);
}
if
(
view
.
glideUrl
!=
null
)
{
FastImageOkHttpProgressGlideModule
.
forget
(
view
.
glideUrl
.
toStringUrl
());
}
...
...
@@ -61,7 +73,9 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
// Cancel existing request.
view
.
glideUrl
=
glideUrl
;
requestManager
.
clear
(
view
);
if
(
requestManager
!=
null
)
{
requestManager
.
clear
(
view
);
}
String
key
=
glideUrl
.
toStringUrl
();
FastImageOkHttpProgressGlideModule
.
expect
(
key
,
this
);
...
...
@@ -80,15 +94,18 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
final
String
stringUrl
=
glideUrl
.
toString
();
requestManager
// This will make this work for remote and local images. e.g.
// - file:///
// - content://
// - data:image/png;base64
.
load
(
stringUrl
.
startsWith
(
"http"
)
?
glideUrl
:
stringUrl
)
.
apply
(
FastImageViewConverter
.
getOptions
(
source
))
.
listener
(
new
FastImageRequestListener
(
key
))
.
into
(
view
);
if
(
requestManager
!=
null
)
{
requestManager
// This will make this work for remote and local images. e.g.
// - file:///
// - content://
// - data:image/png;base64
.
load
(
stringUrl
.
startsWith
(
"http"
)
?
glideUrl
:
stringUrl
)
.
apply
(
FastImageViewConverter
.
getOptions
(
source
))
.
listener
(
new
FastImageRequestListener
(
key
))
.
into
(
view
);
}
}
@ReactProp
(
name
=
"resizeMode"
)
...
...
@@ -100,7 +117,9 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
@Override
public
void
onDropViewInstance
(
FastImageViewWithUrl
view
)
{
// This will cancel existing requests.
requestManager
.
clear
(
view
);
if
(
requestManager
!=
null
)
{
requestManager
.
clear
(
view
);
}
if
(
view
.
glideUrl
==
null
)
{
super
.
onDropViewInstance
(
view
);
return
;
...
...
@@ -153,4 +172,38 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
return
0.5f
;
}
private
static
boolean
isValidContextForGlide
(
final
Context
context
)
{
if
(
context
==
null
)
{
return
false
;
}
if
(
context
instanceof
Activity
)
{
final
Activity
activity
=
(
Activity
)
context
;
if
(
isAcitityDestroyed
(
activity
))
{
return
false
;
}
}
if
(
context
instanceof
ThemedReactContext
)
{
final
Context
baseContext
=
((
ThemedReactContext
)
context
).
getBaseContext
();
if
(
baseContext
instanceof
Activity
)
{
final
Activity
baseActivity
=
(
Activity
)
baseContext
;
if
(
baseActivity
==
null
||
isAcitityDestroyed
(
baseActivity
))
{
return
false
;
}
}
}
return
true
;
}
private
static
boolean
isAcitityDestroyed
(
Activity
activity
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
JELLY_BEAN_MR1
)
{
return
activity
.
isDestroyed
()
||
activity
.
isFinishing
();
}
else
{
return
activity
.
isFinishing
()
||
activity
.
isChangingConfigurations
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment