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
3fa270ed
Commit
3fa270ed
authored
Sep 23, 2015
by
Gaëtan Renaudeau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reorganize code
parent
329faf6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
95 deletions
+100
-95
RNGL/GLCanvas.m
RNGL/GLCanvas.m
+100
-95
No files found.
RNGL/GLCanvas.m
View file @
3fa270ed
...
...
@@ -12,6 +12,20 @@
#import "GLRenderData.h"
#import "UIView+React.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
;
}
// For reference, see implementation of gl-shader's GLCanvas
@implementation
GLCanvas
...
...
@@ -32,8 +46,6 @@
NSMutableArray
*
_preloaded
;
BOOL
_preloadingDone
;
CADisplayLink
*
displayLink
;
NSTimer
*
animationTimer
;
}
...
...
@@ -52,6 +64,8 @@
RCT_NOT_IMPLEMENTED
(
-
init
)
//// Props Setters
-
(
void
)
setImagesToPreload
:(
NSArray
*
)
imagesToPreload
{
if
(
_preloadingDone
)
return
;
...
...
@@ -65,45 +79,12 @@ RCT_NOT_IMPLEMENTED(-init)
_imagesToPreload
=
imagesToPreload
;
}
-
(
void
)
dispatchOnLoad
{
if
(
_onLoad
)
{
[
_bridge
.
eventDispatcher
sendInputEventWithName
:
@"load"
body
:@{
@"target"
:
self
.
reactTag
}];
}
}
-
(
void
)
dispatchOnProgress
:
(
double
)
progress
withLoaded
:(
int
)
loaded
withTotal
:(
int
)
total
{
if
(
_onProgress
)
{
NSDictionary
*
event
=
@{
@"target"
:
self
.
reactTag
,
@"progress"
:
@
(
progress
),
@"loaded"
:
@
(
loaded
),
@"total"
:
@
(
total
)
};
[
_bridge
.
eventDispatcher
sendInputEventWithName
:
@"progress"
body
:
event
];
}
}
-
(
void
)
setOpaque
:(
BOOL
)
opaque
{
_opaque
=
opaque
;
[
self
setNeedsDisplay
];
}
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
;
}
-
(
void
)
setRenderId
:(
NSNumber
*
)
renderId
{
if
(
_nbContentTextures
>
0
)
{
...
...
@@ -141,18 +122,26 @@ NSString* srcResource (id res)
[
self
syncEventsThrough
];
}
-
(
void
)
syncEventsThrough
{
self
.
userInteractionEnabled
=
!
(
_eventsThrough
);
self
.
superview
.
userInteractionEnabled
=
!
(
_eventsThrough
&&
!
_visibleContent
);
}
-
(
void
)
setData
:(
GLData
*
)
data
{
_data
=
data
;
[
self
requestSyncData
];
}
-
(
void
)
setNbContentTextures
:(
NSNumber
*
)
nbContentTextures
{
[
self
resizeUniformContentTextures
:[
nbContentTextures
intValue
]];
_nbContentTextures
=
nbContentTextures
;
}
//// Sync methods (called from props setters)
-
(
void
)
syncEventsThrough
{
self
.
userInteractionEnabled
=
!
(
_eventsThrough
);
self
.
superview
.
userInteractionEnabled
=
!
(
_eventsThrough
&&
!
_visibleContent
);
}
-
(
void
)
requestSyncData
{
[
self
syncData
];
...
...
@@ -275,60 +264,6 @@ NSString* srcResource (id res)
}
}
-
(
int
)
countPreloaded
{
int
nb
=
0
;
for
(
id
toload
in
_imagesToPreload
)
{
if
([
_preloaded
containsObject
:
srcResource
(
toload
)])
nb
++
;
}
return
nb
;
}
-
(
void
)
onImageLoad
:(
NSString
*
)
loaded
{
if
(
!
_preloadingDone
)
{
[
_preloaded
addObject
:
loaded
];
int
count
=
[
self
countPreloaded
];
int
total
=
(
int
)
[
_imagesToPreload
count
];
double
progress
=
((
double
)
count
)
/
((
double
)
total
);
[
self
dispatchOnProgress
:
progress
withLoaded
:
count
withTotal
:
total
];
if
(
count
==
total
)
{
[
self
dispatchOnLoad
];
_preloadingDone
=
true
;
[
self
requestSyncData
];
}
}
else
{
// Any texture image load will trigger a future re-sync of data (if no preloaded)
[
self
requestSyncData
];
}
}
-
(
void
)
setNbContentTextures
:(
NSNumber
*
)
nbContentTextures
{
[
self
resizeUniformContentTextures
:[
nbContentTextures
intValue
]];
_nbContentTextures
=
nbContentTextures
;
}
-
(
void
)
resizeUniformContentTextures
:(
int
)
n
{
[
EAGLContext
setCurrentContext
:
self
.
context
];
int
length
=
(
int
)
[
_contentTextures
count
];
if
(
length
==
n
)
return
;
if
(
n
<
length
)
{
_contentTextures
=
[
_contentTextures
subarrayWithRange
:
NSMakeRange
(
0
,
n
)];
}
else
{
NSMutableArray
*
contentTextures
=
[[
NSMutableArray
alloc
]
initWithArray
:
_contentTextures
];
for
(
int
i
=
(
int
)
[
_contentTextures
count
];
i
<
n
;
i
++
)
{
[
contentTextures
addObject
:[[
GLTexture
alloc
]
init
]];
}
_contentTextures
=
contentTextures
;
}
}
-
(
void
)
syncContentTextures
{
int
i
=
0
;
...
...
@@ -346,6 +281,9 @@ NSString* srcResource (id res)
}
}
//// Draw
-
(
void
)
drawRect
:(
CGRect
)
rect
{
...
...
@@ -427,6 +365,73 @@ NSString* srcResource (id res)
}
}
//// utility methods
-
(
void
)
onImageLoad
:(
NSString
*
)
loaded
{
if
(
!
_preloadingDone
)
{
[
_preloaded
addObject
:
loaded
];
int
count
=
[
self
countPreloaded
];
int
total
=
(
int
)
[
_imagesToPreload
count
];
double
progress
=
((
double
)
count
)
/
((
double
)
total
);
[
self
dispatchOnProgress
:
progress
withLoaded
:
count
withTotal
:
total
];
if
(
count
==
total
)
{
[
self
dispatchOnLoad
];
_preloadingDone
=
true
;
[
self
requestSyncData
];
}
}
else
{
// Any texture image load will trigger a future re-sync of data (if no preloaded)
[
self
requestSyncData
];
}
}
-
(
int
)
countPreloaded
{
int
nb
=
0
;
for
(
id
toload
in
_imagesToPreload
)
{
if
([
_preloaded
containsObject
:
srcResource
(
toload
)])
nb
++
;
}
return
nb
;
}
-
(
void
)
resizeUniformContentTextures
:(
int
)
n
{
[
EAGLContext
setCurrentContext
:
self
.
context
];
int
length
=
(
int
)
[
_contentTextures
count
];
if
(
length
==
n
)
return
;
if
(
n
<
length
)
{
_contentTextures
=
[
_contentTextures
subarrayWithRange
:
NSMakeRange
(
0
,
n
)];
}
else
{
NSMutableArray
*
contentTextures
=
[[
NSMutableArray
alloc
]
initWithArray
:
_contentTextures
];
for
(
int
i
=
(
int
)
[
_contentTextures
count
];
i
<
n
;
i
++
)
{
[
contentTextures
addObject
:[[
GLTexture
alloc
]
init
]];
}
_contentTextures
=
contentTextures
;
}
}
-
(
void
)
dispatchOnLoad
{
if
(
_onLoad
)
{
[
_bridge
.
eventDispatcher
sendInputEventWithName
:
@"load"
body
:@{
@"target"
:
self
.
reactTag
}];
}
}
-
(
void
)
dispatchOnProgress
:
(
double
)
progress
withLoaded
:(
int
)
loaded
withTotal
:(
int
)
total
{
if
(
_onProgress
)
{
NSDictionary
*
event
=
@{
@"target"
:
self
.
reactTag
,
@"progress"
:
@
(
progress
),
@"loaded"
:
@
(
loaded
),
@"total"
:
@
(
total
)
};
[
_bridge
.
eventDispatcher
sendInputEventWithName
:
@"progress"
body
:
event
];
}
}
@end
\ No newline at end of file
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