Comments (4)
sorry,my English is terrible。Unconsciously, I found that this component(react-native-signature-capture) was exactly what I wanted to do。so,i solve it
from react-native-canvas.
this is my code, I want wirte a Handwriting board, user write his name and I send to java as image
import React, { Component } from 'react'
import {
Text,
View,
TouchableOpacity,
DeviceEventEmitter,
PanResponder
} from 'react-native'
import Canvas, { Image as CanvasImage }from 'react-native-canvas'
import { List, Button } from 'antd-mobile'
import RNFetchBlob from 'react-native-fetch-blob'
import styles from '../../style/PurReceive/QualityControl'
import HeaderTwo from '../HeaderTwo'
import config from '../../utils/config'
import Jfetch from '../../utils/Jfetch'
const Item = List.Item
class SignCanvas extends Component {
componentWillMount() {
this._panResponder = PanResponder.create({
// 要求成为响应者:
onStartShouldSetPanResponder: (evt, gestureState) => true,
onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
onPanResponderGrant: (evt, gestureState) => {
// 开始手势操作。给用户一些视觉反馈,让他们知道发生了什么事情!
// gestureState.{x,y}0 现在会被设置为0
},
onPanResponderMove: (evt, gestureState) => {
const canvas = this.refs.canvas
const ctx = canvas.getContext('2d')
ctx.fillStyle = 'purple'
ctx.fillRect(gestureState.moveX, gestureState.moveY - 50, 6, 6)
},
onPanResponderTerminationRequest: (evt, gestureState) => true,
onPanResponderRelease: (evt, gestureState) => {
// 用户放开了所有的触摸点,且此时视图已经成为了响应者。
// 一般来说这意味着一个手势操作已经成功完成。
},
onPanResponderTerminate: (evt, gestureState) => {
// 另一个组件已经成为了新的响应者,所以当前手势将被取消。
},
onShouldBlockNativeResponder: (evt, gestureState) => {
// 返回一个布尔值,决定当前组件是否应该阻止原生组件成为JS响应者
// 默认返回true。目前暂时只支持android。
return true
},
})
}
componentDidMount() {
this.refs.canvas.height = 400
}
d = async () => {
const canvas = this.refs.canvas
const data = await canvas.toDataURL()
return data
}
sign() {
// DeviceEventEmitter.emit('signUrl', 'customSign\\20171113\\upfile-20171113102921104.png')
// const { navigator } = this.props
// if(navigator){
// navigator.pop()
// }
this.d().then(b64=>{
RNFetchBlob.fetch('POST', `${config.apiUrl}/InvStockTake/customSign`, {
// 上传图片要设置Header
'Content-Type' : 'application/octet-stream;BASE64',
}, [
{ name: 'upfile', filename: 'upfile.png', data: b64.split(',')[1] },
])
.then((response)=> response.json())
.then((response)=> {
DeviceEventEmitter.emit('signUrl', response)
const { navigator } = this.props
if(navigator){
navigator.pop()
}
})
.catch((error)=>{
// 错误信息
console.log(error)
})
})
}
render() {
return (<View>
<HeaderTwo title='客户签字' navigator={this.props.navigator} />
<View style={{height: 400}} {...this._panResponder.panHandlers}>
<List className="my-list">
<Item>
<Canvas ref="canvas" style={{height: 400}} />
</Item>
</List>
</View>
<List className="my-list">
<Item extra={<Button type="primary" size="small" style={{height: 30, width: 100}} onPressIn={this.sign.bind(this)} >确认</Button>} />
</List>
</View>)
}
}
export default SignCanvas
from react-native-canvas.
Accidentally turned off
from react-native-canvas.
Hey there @lsdiao thank you for trying react-native-canvas and opening this issue. I find a difficulty to understand what is the problem you're facing. Can you please describe what happens when you run the code in different words?
from react-native-canvas.
Related Issues (20)
- Please help.. HOT 1
- How to add rotate on a dom element like text HOT 1
- No license text HOT 5
- cropping an image HOT 1
- Not able to render image on ios 15.2.1 HOT 3
- Path2D differs from the Canvas API, in that it's not connected to a Canvas element HOT 2
- getcontext of a canvas gives TypeError: canvas.getContext is not a function HOT 2
- Difference in drawImage coordinates and getImageData/putImageData coordinates HOT 2
- why Why did I use getImageData() for more than 1 minute? HOT 2
- Canvas remain black on windows
- How do you get fillRect to occupy full dimensions? HOT 4
- ImageData/getImageData/putImageData strange behaviour HOT 2
- error HOT 2
- require cycle node_modules\react-native-canvas HOT 1
- canvas.loadFromJSON missing in react-native-canvas
- Error: Unable to resolve module ./CanvasRenderingContext2D HOT 1
- Not able to add fontFamily with font
- Application gets hang after 10 mins due to drawing on canvas continuously
- Can't draw image greater than 2048x2048 HOT 1
- Virtual/In-Memory Canvas HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-canvas.