Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
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
love_飞影
Neos
Commits
9fd16189
Commit
9fd16189
authored
Dec 29, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix useClick by rewitten
parent
946e2750
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
20 deletions
+90
-20
src/ui/Duel/hands_.tsx
src/ui/Duel/hands_.tsx
+25
-20
src/ui/Duel/hook.ts
src/ui/Duel/hook.ts
+65
-0
No files found.
src/ui/Duel/hands_.tsx
View file @
9fd16189
...
@@ -10,7 +10,8 @@ import {
...
@@ -10,7 +10,8 @@ import {
setCardModalInteractivies
,
setCardModalInteractivies
,
}
from
"
../../reducers/duel/mod
"
;
}
from
"
../../reducers/duel/mod
"
;
import
{
store
}
from
"
../../store
"
;
import
{
store
}
from
"
../../store
"
;
import
{
useClick
,
useHover
}
from
"
react-babylonjs
"
;
import
{
useHover
}
from
"
react-babylonjs
"
;
import
{
useClick
}
from
"
./hook
"
;
import
{
useState
,
useRef
}
from
"
react
"
;
import
{
useState
,
useRef
}
from
"
react
"
;
const
DuelHands
=
()
=>
{
const
DuelHands
=
()
=>
{
...
@@ -39,7 +40,8 @@ const DuelHand = (props: { state: Card; idx: number }) => {
...
@@ -39,7 +40,8 @@ const DuelHand = (props: { state: Card; idx: number }) => {
planeRef
planeRef
);
);
useClick
(()
=>
{
useClick
(
()
=>
{
dispatch
(
setCardModalText
([
state
.
meta
.
text
.
name
,
state
.
meta
.
text
.
desc
]));
dispatch
(
setCardModalText
([
state
.
meta
.
text
.
name
,
state
.
meta
.
text
.
desc
]));
dispatch
(
dispatch
(
setCardModalImgUrl
(
setCardModalImgUrl
(
...
@@ -57,7 +59,10 @@ const DuelHand = (props: { state: Card; idx: number }) => {
...
@@ -57,7 +59,10 @@ const DuelHand = (props: { state: Card; idx: number }) => {
)
)
);
);
dispatch
(
setCardModalIsOpen
(
true
));
dispatch
(
setCardModalIsOpen
(
true
));
},
planeRef
);
},
planeRef
,
[
state
]
);
return
(
return
(
<>
<>
<
plane
<
plane
...
...
src/ui/Duel/hook.ts
0 → 100644
View file @
9fd16189
// 一些自定义`Hook`
import
{
ActionEvent
}
from
"
@babylonjs/core
"
;
import
{
MutableRefObject
,
useEffect
,
useRef
}
from
"
react
"
;
import
{
Nullable
}
from
"
@babylonjs/core/types.js
"
;
import
{
Mesh
}
from
"
@babylonjs/core/Meshes/mesh.js
"
;
import
{
AbstractMesh
}
from
"
@babylonjs/core/Meshes/abstractMesh.js
"
;
import
{
ActionManager
}
from
"
@babylonjs/core/Actions/actionManager.js
"
;
import
{
IAction
}
from
"
@babylonjs/core/Actions/action.js
"
;
import
{
ExecuteCodeAction
}
from
"
@babylonjs/core/Actions/directActions.js
"
;
export
interface
MeshEventType
{
(
env
:
ActionEvent
):
void
;
}
type
DependencyList
=
ReadonlyArray
<
unknown
>
;
/**
* rewritten useClick hook
*
* origion ref: https://github.com/brianzinn/react-babylonjs/blob/master/packages/react-babylonjs/src/hooks/utilityHooks.ts#L132
*
* Why i rewritten this?: https://github.com/brianzinn/react-babylonjs/issues/209
*
* @param onClick What would be passed in the OnPickTrigger from ActionManager
* @param ownRef to re-use a Ref you already have, otherwise one is created for you and returned.
* @param deps observation object
*/
export
function
useClick
(
onClick
:
MeshEventType
,
ownRef
?:
MutableRefObject
<
Nullable
<
Mesh
>>
,
deps
?:
DependencyList
):
[
MutableRefObject
<
Nullable
<
Mesh
>>
]
{
const
createdRef
=
useRef
<
Nullable
<
Mesh
>>
(
null
);
const
ref
=
ownRef
??
createdRef
;
useEffect
(()
=>
{
if
(
ref
.
current
)
{
if
(
ref
.
current
instanceof
AbstractMesh
)
{
const
mesh
=
ref
.
current
as
Mesh
;
if
(
!
mesh
.
actionManager
)
{
mesh
.
actionManager
=
new
ActionManager
(
mesh
.
getScene
());
}
const
action
:
Nullable
<
IAction
>
=
mesh
.
actionManager
.
registerAction
(
new
ExecuteCodeAction
(
ActionManager
.
OnPickTrigger
,
function
(
ev
:
any
)
{
onClick
(
ev
);
})
);
return
()
=>
{
// unregister on teardown
mesh
.
actionManager
?.
unregisterAction
(
action
!
);
};
}
else
{
console
.
warn
(
"
onClick hook only supports referencing Meshes
"
);
}
}
},
[...(
deps
||
[]),
ref
]);
// todo: if use ref.current as dep, duplicate register action.
return
[
ref
];
}
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