Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
M
manager-app-sz
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
manager-app-sz
Commits
a5c14b5c
提交
a5c14b5c
authored
11月 17, 2017
作者:
吴强
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Camera Screen
上级
c6aa0b65
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
51 行增加
和
46 行删除
+51
-46
cameraComponent.js
src/components/cameraComponent.js
+51
-46
没有找到文件。
src/components/cameraComponent.js
浏览文件 @
a5c14b5c
import
React
from
'react'
;
import
{
View
,
Image
,
StatusBar
,
StyleSheet
,
TouchableOpacity
,
Image
,
Dimensions
,
}
from
'react-native'
;
import
Icon
from
'react-native-vector-icons/MaterialIcons'
;
import
Camera
from
'react-native-camera'
;
...
...
@@ -12,13 +12,15 @@ import Camera from 'react-native-camera';
const
styles
=
StyleSheet
.
create
({
container
:
{
flex
:
1
,
marginTop
:
50
,
},
preview
:
{
flex
:
1
,
justifyContent
:
'flex-end'
,
alignItems
:
'center'
,
},
previewPic
:
{
flex
:
1
,
},
overlay
:
{
position
:
'absolute'
,
padding
:
16
,
...
...
@@ -62,38 +64,28 @@ class CameraComponent extends React.Component {
orientation
:
Camera
.
constants
.
Orientation
.
auto
,
},
isRecording
:
false
,
imageURI
:
''
,
};
this
.
switchCam
=
this
.
switchCam
.
bind
(
this
);
this
.
recording
=
this
.
recording
.
bind
(
this
);
this
.
takePicture
=
this
.
takePicture
.
bind
(
this
);
}
get
typeIcon
()
{
let
icon
;
typeIcon
=
()
=>
{
const
{
back
,
front
}
=
Camera
.
constants
.
Type
;
if
(
this
.
state
.
camera
.
type
===
back
)
{
Icon
.
getImageSource
(
'camera_front'
,
20
,
'white'
).
then
((
source
)
=>
{
console
.
info
(
source
);
icon
=
source
.
uri
;
});
console
.
info
(
icon
);
return
'camera-front'
;
// icon = require('./assets/ic_camera_rear_white.png');
}
else
if
(
this
.
state
.
camera
.
type
===
front
)
{
Icon
.
getImageSource
(
'camera_rear'
,
20
,
'white'
).
then
((
source
)
=>
{
console
.
info
(
source
);
icon
=
source
.
uri
;
});
// icon = require('./assets/ic_camera_front_white.png');
console
.
info
(
icon
);
return
'camera-rear'
;
}
return
icon
;
}
get
camButton
()
{
let
img
;
camButton
=
()
=>
{
if
(
!
this
.
state
.
isRecording
)
{
Icon
.
getImageSource
(
'videocam'
,
36
,
'white'
).
then
((
source
)
=>
{
console
.
info
(
source
);
img
=
source
.
uri
;
});
// img = require('./assets/ic_videocam_36pt.png');
console
.
info
(
img
);
return
'videocam'
;
}
else
{
// img = require('./assets/ic_stop_36pt.png');
Icon
.
getImageSource
(
'stop'
,
36
,
'white'
).
then
((
source
)
=>
{
console
.
info
(
source
);
img
=
source
.
uri
;
});
console
.
info
(
img
);
return
'stop'
;
}
return
img
;
}
switchCam
()
{
let
newType
;
...
...
@@ -131,34 +123,47 @@ class CameraComponent extends React.Component {
console
.
log
(
'stopped '
);
}
}
takePicture
()
{
const
options
=
{
mode
:
Camera
.
constants
.
CaptureMode
.
still
};
this
.
camera
.
capture
({
metadata
:
options
})
.
then
((
data
)
=>
{
console
.
log
(
data
);
this
.
setState
({
imageURI
:
data
.
path
});
})
.
catch
(
err
=>
console
.
error
(
err
));
}
render
()
{
return
(
<
View
style
=
{
styles
.
container
}
>
<
StatusBar
animated
hidden
=
{
false
}
/
>
<
Camera
ref
=
{(
cam
)
=>
{
this
.
camera
=
cam
;
}}
style
=
{
styles
.
preview
}
aspect
=
{
this
.
state
.
camera
.
aspect
}
captureTarget
=
{
this
.
state
.
camera
.
captureTarge
t
}
type
=
{
this
.
state
.
camera
.
type
}
defaultTouchToFocus
mirrorImage
=
{
false
}
/
>
<
View
style
=
{[
styles
.
overlay
,
styles
.
topOverlay
]}
>
<
TouchableOpacity
style
=
{
styles
.
typeButton
}
onPress
=
{
this
.
switchCam
}
>
<
I
mage
source
=
{
this
.
typeIcon
}
/
>
<
/TouchableOpacity
>
<
/View
>
<
View
style
=
{[
styles
.
overlay
,
styles
.
bottomOverlay
]}
>
<
TouchableOpacity
style
=
{
styles
.
captureButton
}
onPress
=
{
this
.
recording
}
>
<
I
mage
source
=
{
this
.
camButton
}
/
>
<
/
TouchableOpacity
>
if
(
this
.
state
.
imageURI
===
''
)
{
return
(
<
View
style
=
{
styles
.
container
}
>
<
StatusBar
animated
hidden
/>
<
Camera
ref
=
{(
cam
)
=>
{
this
.
camera
=
cam
;
}
}
style
=
{
styles
.
preview
}
aspect
=
{
this
.
state
.
camera
.
aspec
t
}
captureTarget
=
{
this
.
state
.
camera
.
captureTarget
}
type
=
{
this
.
state
.
camera
.
type
}
defaultTouchToFocus
mirrorImage
=
{
false
}
/
>
<
View
style
=
{[
styles
.
overlay
,
styles
.
topOverlay
]
}
>
<
I
con
.
Button
name
=
{
this
.
typeIcon
()}
size
=
{
36
}
backgroundColor
=
"transparent"
onPress
=
{
this
.
switchCam
}
/
>
<
Icon
.
Button
name
=
{
this
.
typeIcon
()}
size
=
{
36
}
backgroundColor
=
"transparent"
onPress
=
{
this
.
switchCam
}
/
>
<
/View
>
<
View
style
=
{[
styles
.
overlay
,
styles
.
bottomOverlay
]}
>
<
Icon
.
Button
name
=
"photo-camera"
size
=
{
48
}
backgroundColor
=
"transparent"
onPress
=
{
this
.
takePicture
}
/
>
<
I
con
.
Button
name
=
{
this
.
camButton
()}
size
=
{
48
}
backgroundColor
=
"transparent"
onPress
=
{
this
.
recording
}
/
>
<
/
View
>
<
/View
>
<
/View
>
);
);
}
else
{
return
(
<
Image
style
=
{{
height
:
Dimensions
.
get
(
'window'
).
height
,
width
:
Dimensions
.
get
(
'window'
).
width
}}
source
=
{{
uri
:
this
.
state
.
imageURI
,
isStatic
:
true
}}
/
>
);
}
}
}
export
default
CameraComponent
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论