Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gl-react-native-v2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ym
gl-react-native-v2
Commits
6fc8611f
Commit
6fc8611f
authored
Feb 19, 2016
by
Gaëtan Renaudeau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
iOS: use RCTImageSource to support exactly the same Image source
parent
bcb07dcb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
49 deletions
+39
-49
ios/GLCanvas.m
ios/GLCanvas.m
+28
-32
ios/GLImage.h
ios/GLImage.h
+2
-1
ios/GLImage.m
ios/GLImage.m
+9
-16
No files found.
ios/GLCanvas.m
View file @
6fc8611f
...
...
@@ -11,18 +11,10 @@
#import "GLImage.h"
#import "GLRenderData.h"
#import "UIView+React.h"
#import "RCTImageSource.h"
NSString
*
srcResource
(
id
res
)
{
NSString
*
src
;
if
([
res
isKindOfClass
:[
NSString
class
]])
{
src
=
[
RCTConvert
NSString
:
res
];
}
else
{
BOOL
isStatic
=
[
RCTConvert
BOOL
:
res
[
@"isStatic"
]];
src
=
[
RCTConvert
NSString
:
res
[
@"path"
]];
if
(
!
src
||
isStatic
)
src
=
[
RCTConvert
NSString
:
res
[
@"uri"
]];
}
return
src
;
NSString
*
imageSourceHash
(
RCTImageSource
*
is
)
{
return
is
.
imageURL
.
absoluteString
;
}
NSArray
*
diff
(
NSArray
*
a
,
NSArray
*
b
)
{
...
...
@@ -250,27 +242,31 @@ RCT_NOT_IMPLEMENTED(-init)
textures
[
uniformName
]
=
fbo
.
color
[
0
];
}
else
if
([
type
isEqualToString
:
@"uri"
])
{
NSString
*
src
=
srcResource
(
value
)
;
RCTImageSource
*
src
=
[
RCTConvert
RCTImageSource
:
value
]
;
if
(
!
src
)
{
RCTLogError
(
@"texture uniform '%@': Invalid uri format '%@'"
,
uniformName
,
value
);
GLTexture
*
emptyTexture
=
[[
GLTexture
alloc
]
init
];
[
emptyTexture
setPixels
:
nil
];
textures
[
uniformName
]
=
emptyTexture
;
}
GLImage
*
image
=
images
[
src
];
else
{
NSString
*
key
=
imageSourceHash
(
src
);
GLImage
*
image
=
images
[
key
];
if
(
image
==
nil
)
{
image
=
prevImages
[
src
];
image
=
prevImages
[
key
];
if
(
image
!=
nil
)
images
[
src
]
=
image
;
images
[
key
]
=
image
;
}
if
(
image
==
nil
)
{
__weak
GLCanvas
*
weakSelf
=
self
;
image
=
[[
GLImage
alloc
]
initWithBridge
:
_bridge
withOnLoad
:
^
{
if
(
weakSelf
)
[
weakSelf
onImageLoad
:
src
];
}];
image
.
src
=
src
;
images
[
src
]
=
image
;
image
.
source
=
src
;
images
[
key
]
=
image
;
}
textures
[
uniformName
]
=
[
image
getTexture
];
}
}
else
{
RCTLogError
(
@"texture uniform '%@': Unexpected type '%@'"
,
uniformName
,
type
);
}
...
...
@@ -354,7 +350,7 @@ RCT_NOT_IMPLEMENTED(-init)
-
(
BOOL
)
haveRemainingToPreload
{
for
(
id
res
in
_imagesToPreload
)
{
if
(
!
[
_preloaded
containsObject
:
srcResource
(
res
)])
{
if
(
!
[
_preloaded
containsObject
:
imageSourceHash
([
RCTConvert
RCTImageSource
:
res
]
)])
{
return
true
;
}
}
...
...
@@ -552,9 +548,9 @@ RCT_NOT_IMPLEMENTED(-init)
//// utility methods
-
(
void
)
onImageLoad
:(
NSString
*
)
loaded
-
(
void
)
onImageLoad
:(
RCTImageSource
*
)
source
{
[
_preloaded
addObject
:
loaded
];
[
_preloaded
addObject
:
imageSourceHash
(
source
)
];
int
count
=
[
self
countPreloaded
];
int
total
=
(
int
)
[
_imagesToPreload
count
];
double
progress
=
((
double
)
count
)
/
((
double
)
total
);
...
...
@@ -567,7 +563,7 @@ RCT_NOT_IMPLEMENTED(-init)
{
int
nb
=
0
;
for
(
id
toload
in
_imagesToPreload
)
{
if
([
_preloaded
containsObject
:
srcResource
(
toload
)])
if
([
_preloaded
containsObject
:
imageSourceHash
([
RCTConvert
RCTImageSource
:
toload
]
)])
nb
++
;
}
return
nb
;
...
...
ios/GLImage.h
View file @
6fc8611f
#import "RCTBridge.h"
#import "GLTexture.h"
#import "RCTImageSource.h"
@interface
GLImage
:
NSObject
@property
(
nonatomic
,
copy
)
NSString
*
src
;
@property
(
nonatomic
,
copy
)
RCTImageSource
*
source
;
@property
(
nonatomic
)
UIImage
*
image
;
...
...
ios/GLImage.m
View file @
6fc8611f
...
...
@@ -60,10 +60,10 @@ RCT_NOT_IMPLEMENTED(-init)
return
_texture
;
}
-
(
void
)
setS
rc
:(
NSString
*
)
src
-
(
void
)
setS
ource
:(
RCTImageSource
*
)
source
{
if
(
!
[
s
rc
isEqualToString
:
_src
])
{
_s
rc
=
[
src
copy
]
;
if
(
!
[
s
ource
isEqual
:
_source
])
{
_s
ource
=
source
;
[
self
reloadImage
];
}
}
...
...
@@ -72,22 +72,15 @@ RCT_NOT_IMPLEMENTED(-init)
{
if
(
_loading
)
_loading
();
_loading
=
nil
;
if
(
!
_s
rc
)
{
if
(
!
_s
ource
)
{
[
self
clearImage
];
}
else
{
}
else
{
// Load the image (without resizing it)
if
(
!
[
_src
hasPrefix
:
@"http://"
]
&&
!
[
_src
hasPrefix
:
@"https://"
])
{
self
.
image
=
[
UIImage
imageNamed
:
_src
];
dispatch_async
(
dispatch_get_main_queue
(),
^
{
if
(
_onload
)
_onload
();
});
}
else
{
_loading
=
[
_bridge
.
imageLoader
loadImageWithTag
:
_src
_loading
=
[
_bridge
.
imageLoader
loadImageWithoutClipping
:
_source
.
imageURL
.
absoluteString
size:
CGSizeZero
scale:
0
resizeMode:
UIViewContentModeScaleToFill
resizeMode:
RCTResizeModeStretch
progressBlock:
nil
completionBlock:
^
(
NSError
*
error
,
UIImage
*
image
)
{
_loading
=
nil
;
...
...
@@ -96,6 +89,7 @@ RCT_NOT_IMPLEMENTED(-init)
NSLog
(
@"Image failed to load: %@"
,
error
);
}
else
{
// we need to copy the image because it seems the image will be altered.
// ^^^ FIXME: check if it's still the case
self
.
image
=
[
UIImage
imageWithCGImage
:
image
.
CGImage
];
dispatch_async
(
dispatch_get_main_queue
(),
^
{
if
(
_onload
)
_onload
();
...
...
@@ -103,7 +97,6 @@ RCT_NOT_IMPLEMENTED(-init)
}
}];
}
}
}
...
...
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