How to use getHeight method in Testcafe

Best JavaScript code snippet using testcafe

UploadsPage.js

Source:UploadsPage.js Github

copy

Full Screen

1import React from 'react';2import {3 View,4 Text,5 ScrollView,6 TouchableOpacity,7 Image,8 Alert,9 Dimensions,10 Modal,11} from 'react-native';12import {Button} from 'react-native-paper';13import ImageView from 'react-native-image-view';14import {TextInput, Switch} from 'react-native-paper';15import Icon from 'react-native-vector-icons/dist/AntDesign';16import AsyncStorage from '@react-native-community/async-storage';17import {StackActions} from '@react-navigation/native';18import axios from 'axios';19import Buffer from 'buffer';20import {ActivityIndicator, Colors} from 'react-native-paper';21import {GetHeight, GetWidth} from './utils/utils';22import ImagePicker from 'react-native-image-crop-picker';23import Ionicons from 'react-native-vector-icons/Ionicons';24var Dim = {25 width: Dimensions.get('window').width,26 height: Dimensions.get('window').height,27};2829// Functional component to present image cards30function ImageCard(props) {31 return (32 <View33 style={{34 height: GetHeight(61, 640),35 elevation: 5,36 marginHorizontal: GetWidth(0, 360),37 marginVertical: GetWidth(10, 360),38 backgroundColor: '#FFFFFF',39 padding: GetHeight(7, 640),40 justifyContent: 'center',41 }}>42 <View style={{flexDirection: 'row', justifyContent: 'space-between'}}>43 <View style={{flexDirection: 'row'}}>44 <TouchableOpacity onPress={props.preview}>45 <Image46 source={{uri: props.path}}47 style={{48 height: GetHeight(46, 640),49 width: GetHeight(46, 640),50 borderRadius: GetHeight(5, 640),51 }}52 resizeMode="contain"53 />54 </TouchableOpacity>55 <View56 style={{57 paddingLeft: 10,58 width: Dim.width * 0.4,59 justifyContent: 'center',60 }}>61 <Text62 numberOfLines={1}63 ellipsizeMode="tail"64 style={{65 fontSize: GetHeight(12, 640),66 color: '#5859ED',67 }}>68 {props.name}69 </Text>70 </View>71 </View>72 <View73 style={{74 justifyContent: 'center',75 }}>76 <TouchableOpacity onPress={() => props.remove()}>77 <Image78 style={{79 height: GetHeight(20, 640),80 width: GetHeight(20, 640),81 }}82 resizeMode="contain"83 source={require('../assets/images/remove.png')}84 />85 </TouchableOpacity>86 </View>87 </View>88 </View>89 );90}9192// Function to remove duplicate tags93function RemoveDuplicates( tags ) {94 let newTaglist = [];95 tags.sort((a,b) => a.value < b.value ? -1: 1);96 if (tags.length >0)97 newTaglist.push(tags[0])98 let a = 0, b = 0;99 while ( a < tags.length) {100 while ( b < tags.length ) {101 if ( tags[a].value == tags[b].value ) {102 b += 1;103 } else {104 newTaglist.push(tags[b]);105 a = b;106 }107 }108 a += 1;109 }110 return newTaglist;111}112113function TagsCard(tags, pushCap, handleHashtags) {114 let tagsChips = tags.map((value, index) => (115 <TouchableOpacity116 key={index}117 style={{margin: GetHeight(2,640), backgroundColor: ( value.selected ) ? '#5859ED' : '#707070' }}118 onPress={() => {119 pushCap(value.value);120 handleHashtags(value.value);121 }}>122 <Text style={{color: 'white', fontSize: GetHeight(12,640), marginHorizontal: GetWidth(16,360), marginVertical: GetHeight(8,640)}}>123 {value.value}124 </Text>125 </TouchableOpacity>126 ));127 return tagsChips;128}129130/*131132The following fuctions handle upload to a specific platform.133 - UploadToFacebook134 - handleLinkedinUpload135 - handleTwitterUpload136137params:138 - images139 * Takes in array of images140 - caption/status141 * Taken in caption to post142 */143144async function UploadToFacebook(images, caption) {145 return new Promise(async (resolve, reject) => {146 let token = await AsyncStorage.getItem('facebookAccessToken');147 let vectorToStoreImageIDs = [];148 let url_to_upload_photo = `https://graph.facebook.com/v6.0/me/photos?access_token=${token}&published=false`;149 for (const {uri, name, type} of images) {150 let dataForm = new FormData();151 dataForm.append('source', {152 uri: uri,153 type: type,154 name: name,155 });156 const config = {157 method: 'post',158 url: url_to_upload_photo,159 data: dataForm,160 headers: {161 Accept: 'application/json',162 'Content-Type': 'multipart/form-data',163 },164 };165 try {166 let response = await axios(config);167 vectorToStoreImageIDs.push(response.data.id);168 } catch (e) {169 reject({170 status: 1,171 message: e,172 });173 }174 }175 let baseurl = 'https://graph.facebook.com/v2.11/me/feed?';176 baseurl += `access_token=${token}&message=${encodeURIComponent(caption)}`;177 for (let i in vectorToStoreImageIDs) {178 baseurl += `&attached_media[${i}]={"media_fbid":"${179 vectorToStoreImageIDs[i]180 }"}`;181 }182 try {183 await axios.post(baseurl);184 } catch (e) {185 reject({186 status: 1,187 message: e,188 });189 }190191 resolve({192 status: 0,193 message: 'successful!',194 });195 });196}197async function handleLinkedinUpload(images, status) {198 return new Promise(async (resolve, reject) => {199 let AccessToken = await AsyncStorage.getItem('linkedinAccessToken');200 let owner = await AsyncStorage.getItem('LinkedinOrgIn');201 console.log(owner);202 //let owner = `urn:li:organization:${orgId}`;203 let cap = '';204 for (let i in status) {205 if (status.charCodeAt(i) == 10) {206 cap += '\\n';207 } else {208 cap += status[i];209 }210 }211 status = cap;212 let assets = [];213 for (var img of images) {214 var raw = JSON.stringify({215 registerUploadRequest: {216 owner: owner,217 recipes: ['urn:li:digitalmediaRecipe:feedshare-image'],218 serviceRelationships: [219 {220 identifier: 'urn:li:userGeneratedContent',221 relationshipType: 'OWNER',222 },223 ],224 },225 }); // End of payload for Upload Registration226227 var requestOptions = {228 method: 'POST',229 headers: {230 Authorization: `Bearer ${AccessToken}`,231 'Content-Type': 'application/json',232 },233 body: raw,234 redirect: 'follow',235 };236 let resp, response;237 try {238 resp = await fetch(239 'https://api.linkedin.com/v2/assets?action=registerUpload',240 requestOptions,241 );242 response = await resp.json();243 } catch (e) {244 reject({245 status: 1,246 message: e,247 });248 }249 let url =250 response.value.uploadMechanism[251 'com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest'252 ].uploadUrl;253 let asset = response.value.asset;254 assets.push(asset);255 const buffer = Buffer.Buffer.from(img.data, 'base64');256 try {257 let resp = await fetch(url, {258 method: 'POST',259 headers: {260 Authorization: `Bearer ${AccessToken}`,261 'Content-Type': `${img.type}; charset=utf-8`,262 'x-amz-acl': 'public-read',263 },264 body: buffer,265 redirect: 'follow',266 });267 } catch (e) {268 reject({269 status: 1,270 message: e,271 });272 }273 }274 let entity = assets.map((value, i) => {275 return {276 entity: value,277 };278 });279280 let finalPayload = `{"content": {"contentEntities": ${JSON.stringify(281 entity,282 )},"description": "content description","title": "Images uploaded","shareMediaCategory": "IMAGE"},"distribution": {"linkedInDistributionTarget": {}},"owner": "${owner}","subject": "Parallel Upload Content","text": {"text": "${status}"}}`;283 var requestOptions = {284 method: 'POST',285 headers: {286 Authorization: `Bearer ${AccessToken}`,287 'Content-Type': 'application/json',288 },289 body: finalPayload,290 redirect: 'follow',291 };292293 try {294 let response = await fetch(295 'https://api.linkedin.com/v2/shares',296 requestOptions,297 );298 console.log(await response.text())299 } catch (e) {300 reject({301 status: 1,302 message: e,303 });304 }305 resolve({306 status: 0,307 message: 'successful!',308 });309 });310}311async function handleTwitterUpload(images, caption) {312 return new Promise(async (resolve, reject) => {313 let key = await AsyncStorage.getItem('tweetKey');314 let Secret = await AsyncStorage.getItem('tweetSecret');315 let formData = new FormData();316 let url = 'https://parallel-upload.herokuapp.com/api/v1/tweet';317 formData.append('accessToken', key);318 formData.append('accessTokenSecret', Secret);319 formData.append('status', caption);320 for (var img of images) {321 formData.append('images-base64', img.data);322 }323 let resp = await fetch(url, {324 method: 'post',325 body: formData,326 headers: {327 'Content-Type': 'multipart/form-data',328 },329 }).catch(err => Alert.alert('Network Error', 'Twitter! Error' + err));330 if (resp.status == 200) {331 resolve({332 status: 0,333 message: 'successful!',334 });335 } else {336 reject({337 status: 1,338 message: 'Error occured!',339 });340 }341 });342}343344345/*346 The fuctional component - UploadStatusModal - presents the real time status of the uploads.347 */348function UploadStatusModal(props) {349 const {350 currentQueue,351 totalQueue,352 status,353 uploadQueue,354 setMainPageState,355 GoHome,356 Close,357 TryAgain,358 } = props;359 const STATUS_ICON = {360 success: 'md-checkmark',361 wait: 'ios-timer',362 error: 'md-close',363 };364365 const STATUS_COLOR = {366 success: '#5859ED',367 wait: '#5859ED',368 error: '#EA1152',369 };370371 if (status == 'wait') {372 return (373 <Modal374 animationType="fade"375 transparent={true}376 visible={true}377 hardwareAccelerated={true}>378 <View379 style={{380 flex: 1,381 alignItems: 'center',382 justifyContent: 'center',383 backgroundColor: 'rgba(0,0,0,0.75)',384 }}>385 <View386 style={{387 backgroundColor: '#FFFFFF',388 alignItems: 'center',389 }}>390 <View391 style={{392 backgroundColor: '#5859ED',393 height: GetHeight(80, 640),394 width: GetHeight(80, 640),395 borderRadius: GetHeight(40, 640),396 position: 'relative',397 top: -1 * GetHeight(40, 640),398 alignItems: 'center',399 justifyContent: 'center',400 }}>401 <Ionicons402 name={'ios-timer'}403 size={GetHeight(50, 640)}404 color={'white'}405 />406 </View>407 <View408 style={{409 alignItems: 'center',410 }}>411 <Text412 style={{413 fontSize: GetHeight(26, 640),414 fontWeight: 'bold',415 color: '#5859ED',416 }}>417 Uploading...418 </Text>419 <Text420 style={{421 fontSize: GetHeight(16, 640),422 fontWeight: 'bold',423 color: '#5859ED',424 }}>425 Posted to {currentQueue}/{totalQueue} accounts.426 </Text>427 </View>428 <Button429 onPress={() => {}}430 disabled={true}431 mode={'contained'}432 color={'#5859ED'}433 style={{434 height: GetHeight(41, 640),435 width: GetWidth(247, 360),436 borderRadius: 0,437 elevation: 0,438 marginHorizontal: GetWidth(28, 360),439 marginVertical: GetHeight(28, 640),440 }}441 uppercase={false}442 contentStyle={{443 height: GetHeight(41, 640),444 width: GetWidth(247, 360),445 }}446 labelStyle={{447 fontSize: GetHeight(14, 640),448 }}>449 Done450 </Button>451 </View>452 </View>453 </Modal>454 );455 } else if (status == 'success') {456 return (457 <Modal458 animationType="fade"459 transparent={true}460 visible={true}461 hardwareAccelerated={true}>462 <View463 style={{464 flex: 1,465 alignItems: 'center',466 justifyContent: 'center',467 backgroundColor: 'rgba(0,0,0,0.75)',468 }}>469 <View470 style={{471 backgroundColor: '#FFFFFF',472 alignItems: 'center',473 }}>474 <View475 style={{476 backgroundColor: STATUS_COLOR.success,477 height: GetHeight(80, 640),478 width: GetHeight(80, 640),479 borderRadius: GetHeight(40, 640),480 position: 'relative',481 top: -1 * GetHeight(40, 640),482 alignItems: 'center',483 justifyContent: 'center',484 }}>485 <Ionicons486 name={STATUS_ICON.success}487 size={GetHeight(50, 640)}488 color={'white'}489 />490 </View>491 <View492 style={{493 alignItems: 'center',494 }}>495 <Text496 style={{497 fontSize: GetHeight(26, 640),498 fontWeight: 'bold',499 color: '#5859ED',500 }}>501 Success!502 </Text>503 <Text504 style={{505 fontSize: GetHeight(16, 640),506 fontWeight: 'bold',507 color: '#5859ED',508 }}>509 Posted to all selected accounts.510 </Text>511 </View>512 <Button513 onPress={() => {514 setMainPageState({515 uploadStatusPayload: {516 status: '',517 currentQueue: 0,518 totalQueue: 0,519 uploadQueue: [],520 },521 });522 GoHome();523 }}524 disabled={false}525 mode={'contained'}526 color={'#5859ED'}527 style={{528 height: GetHeight(41, 640),529 width: GetWidth(247, 360),530 borderRadius: 0,531 elevation: 0,532 marginHorizontal: GetWidth(28, 360),533 marginVertical: GetHeight(28, 640),534 }}535 uppercase={false}536 contentStyle={{537 height: GetHeight(41, 640),538 width: GetWidth(247, 360),539 }}540 labelStyle={{541 fontSize: GetHeight(14, 640),542 }}>543 Done544 </Button>545 </View>546 </View>547 </Modal>548 );549 } else if (status == 'error') {550 let payload = {}551 // Making a map to present status of all social Media accounts.552 let SSNStatus = uploadQueue.map((value, index) => {553 console.log(value);554 const {status} = value.status;555 const status_value = status == 0 ? 'success' : 'error';556 if (status == 0) {557 if (value.name == 'facebook') {558 payload = {...payload, facebookPublish: false}559 } else if (value.name == 'twitter') {560 payload = {...payload, twitterPublish: false}561 } else if (value.name == 'linkedin') {562 payload = {...payload, linkedinPublish: false}563 }564 }565 return (566 <View567 key={index}568 style={{569 flexDirection: 'row',570 width: GetWidth(150, 360),571 alignItems: 'stretch',572 marginTop: GetHeight(10, 640),573 justifyContent: 'space-between',574 }}>575 <View576 style={{577 flexDirection: 'row',578 }}>579 <Icon580 name={value.icon}581 size={GetHeight(21, 640)}582 color={STATUS_COLOR[status_value]}583 />584 <View585 style={{586 width: GetWidth(8, 360),587 }}588 />589 <Text590 style={{591 color: STATUS_COLOR[status_value],592 fontWeight: 'bold',593 fontSize: GetHeight(17, 640),594 }}>595 {value.name}596 </Text>597 </View>598 <View>599 <Ionicons600 name={STATUS_ICON[status_value]}601 size={GetHeight(21, 640)}602 color={STATUS_COLOR[status_value]}603 />604 </View>605 </View>606 );607 });608 return (609 <Modal610 animationType="fade"611 transparent={true}612 visible={true}613 hardwareAccelerated={true}>614 <View615 style={{616 flex: 1,617 alignItems: 'center',618 justifyContent: 'center',619 backgroundColor: 'rgba(0,0,0,0.75)',620 }}>621 <View622 style={{623 backgroundColor: '#FFFFFF',624 alignItems: 'center',625 }}>626 <View627 style={{628 backgroundColor: STATUS_COLOR.error,629 height: GetHeight(80, 640),630 width: GetHeight(80, 640),631 borderRadius: GetHeight(40, 640),632 position: 'absolute',633 top: -1 * GetHeight(40, 640),634 alignItems: 'center',635 justifyContent: 'center',636 }}>637 <Ionicons638 name={STATUS_ICON.error}639 size={GetHeight(50, 640)}640 color={'white'}641 />642 </View>643 <View644 style={{645 height: GetHeight(43, 640),646 }}647 />648 <View649 style={{650 margin: 10,651 alignItems: 'center',652 }}>653 <Text654 style={{655 fontSize: GetHeight(26, 640),656 fontWeight: 'bold',657 color: STATUS_COLOR.error,658 }}>659 Error660 </Text>661 <Text662 style={{663 fontSize: GetHeight(16, 640),664 fontWeight: 'bold',665 }}>666 Couldn't post to one or more accounts.667 </Text>668 <View>{SSNStatus}</View>669 </View>670 <View671 style={{672 flexDirection: 'row',673 }}>674 <Button675 onPress={() => {676 Close();677 }}678 mode={'outlined'}679 color={'#5859ED'}680 style={{681 height: GetHeight(41, 640),682 width: GetWidth(109, 360),683 borderRadius: 0,684 elevation: 0,685 borderWidth: 2,686 justifyContent: 'center',687 alignItems: 'center',688 borderColor: '#5859ED',689 marginVertical: GetHeight(28, 640),690 }}691 uppercase={false}692 contentStyle={{693 borderRadius: 0,694 height: GetHeight(41, 640),695 width: GetWidth(109, 360),696 }}697 labelStyle={{698 fontSize: GetHeight(14, 640),699 }}>700 Close701 </Button>702 <View703 style={{704 width: GetWidth(19, 360),705 }}706 />707 <Button708 onPress={() => {709 TryAgain(payload);710 }}711 mode={'contained'}712 color={'#5859ED'}713 style={{714 height: GetHeight(41, 640),715 width: GetWidth(109, 360),716 borderRadius: 0,717 elevation: 0,718 marginVertical: GetHeight(28, 640),719 justifyContent: 'center',720 alignItems: 'center',721 }}722 uppercase={false}723 contentStyle={{724 height: GetHeight(41, 640),725 width: GetWidth(109, 360),726 }}727 labelStyle={{728 fontSize: GetHeight(14, 640),729 }}>730 Try Again731 </Button>732 </View>733 </View>734 </View>735 </Modal>736 );737 } else {738 return null;739 }740}741export default class UploadsPage extends React.Component {742 state = {743 showImage: false,744 Images: [],745 caption: '',746 facebookPublish: false,747 linkedinPublish: false,748 twitterPublish: false,749 tags: [],750 pressGETTags: false,751 uploadStatusPayload: {752 status: '',753 currentQueue: 0,754 totalQueue: 0,755 uploadQueue: [],756 },757 };758759 // Fuction handles add image button760 _handleImageAdd = async () => {761 try {762 let Images = await ImagePicker.openPicker({763 multiple: true,764 includeBase64: true,765 });766 let img = Images.map(value => {767 let _m = value.path.split('/');768 _m = _m[_m.length - 1];769 return {770 width: value.width,771 height: value.height,772 name: _m,773 data: value.data,774 type: value.mime,775 uri: value.path,776 };777 });778 this.setState({779 Images: [...this.state.Images, ...img],780 });781 } catch (e) {782 Alert.alert('Something went wrong!', 'An error occured ' + e);783 }784 };785786 // Handles image preview787 _handlePreview = element => {788 this.setState({789 image: [790 {791 source: {792 uri: element.uri,793 },794 title: 'Preview',795 height: element.height,796 width: element.width,797 },798 ],799 showImage: true,800 });801 };802803 // Handles removing image cards804 _handleImageRemoveButton = uri => {805 if (this.state.Images.length == 1) {806 this.props.navigation.pop();807 }808 let img = [];809 this.state.Images.forEach(value => {810 if (value.uri != uri) {811 img.push(value);812 }813 });814 this.setState({815 Images: img,816 });817 };818819 // Handles adding hastag to caption820 _handlePushCaption = text => {821 this.setState({822 caption: this.state.caption + ' #' + text,823 });824 };825826 // Handles network request to get hashtags suggestions827 _handleGETTags = async () => {828 this.setState({829 pressGETTags: true,830 });831 try {832 let data = await fetch(833 `https://hashtags-suggestion.herokuapp.com/caption?text=${834 this.state.caption835 }`,836 );837 let jsonData = await data.json();838 let tagList = [];839 if (data.status == 200) {840 jsonData.hashtags.forEach((value, i) => {841 tagList.push({value: value.value, selected: false, id: i});842 });843 }844 this.setState({845 tags: RemoveDuplicates([...this.state.tags,...tagList]),846 pressGETTags: false,847 });848 this._handleHashtagGETButton()849 } catch (e) {850 Alert.alert('Network Error', 'Error fetching the hashtags!\n' + e);851 this.setState({852 pressGETTags: false,853 });854 }855 };856857 UNSAFE_componentWillMount() {858 this._updateToken();859 this._LoadTopTenHashtags();860 this.setState({861 Images: this.props.route.params.Images,862 });863 }864865 // Fetches Auth Token for different account866 _updateToken = async () => {867 this.setState({868 facebookPageAccessToken: await AsyncStorage.getItem(869 'facebookAccessToken',870 ),871 twitterAccessToken: await AsyncStorage.getItem('tweetKey'),872 twitterAccessTokenSecret: await AsyncStorage.getItem('tweetSecret'),873 linkedinAccessToken: await AsyncStorage.getItem('linkedinAccessToken'),874 });875 };876877 // Scans the captions to fetch hastags manually entered and adds them to the suggestions.878 _handleHashtagInput = async ( caption ) => {879 const {tags} = this.state;880 let hashtags = caption.match(/#[\p{L}]+/ugi) || []881 tags.sort( (a,b) => a.value < b.value ? -1 : 1);882 hashtags.sort( (a,b) => a.value < b.value ? -1 : 1);883884 console.log(tags, hashtags);885886 for ( let i in tags ) {887 tags[i].selected = false;888 }889 for ( let v of hashtags ) {890 for ( let i in tags ) {891 console.log(v, '#'+tags[i].value )892 if ( v == '#'+tags[i].value ) {893 tags[i].selected = true;894 break;895 }896 }897 }898 // while (i < tags.length) {899 // tags[i].selected = false;900 // i+=1;901 // }902 console.log(tags);903904 this.setState({ tags })905 }906907 // Handles SELECTED status of each Hashtag suggeted CHIP908 _handleHashtagButtonPress = async ( tag ) => {909 let { tags } = this.state;910 for (let x in tags) {911 if ( (tags[x].value) == tag )912 tags[x].selected = true;913 }914 this.setState({ tags })915 }916917 // Function handles displaying top 10 hashtags from hashtag table data store918 _LoadTopTenHashtags = async () => {919 let STORED_HASHTAGS = JSON.parse(await AsyncStorage.getItem('HASHTAGS')) || [];920 STORED_HASHTAGS.sort( (a,b) => a.count > b.count ? -1: 1 );921 let TagsToAdd = []922923 let maxLen = (11 < STORED_HASHTAGS.length) ? 11 : STORED_HASHTAGS.length;924925 let i = 0;926927 while ( i < maxLen ) {928 let name = STORED_HASHTAGS[i].name;929 TagsToAdd.push ({930 value: name.slice(1,name.length),931 selected: false,932 id: 999 - i,933 })934 i+=1;935 }936 this.setState({937 tags: RemoveDuplicates([...this.state.tags, ...TagsToAdd])938 })939 }940941 // Function handles the hashtags data store942 AddHashtagsToStore = async () => {943 let STORED_HASHTAGS = JSON.parse(await AsyncStorage.getItem('HASHTAGS')) || [];944 STORED_HASHTAGS.sort( (a,b) => a.name < b.name ? -1: 1 );945 const {caption} = this.state;946 let hashtags = [...(new Set(caption.match(/#[\p{L}]+/ugi)))] || []947 hashtags.sort( (a,b) => a.name < b.name ? -1: 1)948 let i = 0;949 let j = 0;950 while (i < hashtags.length) {951 while ( j < STORED_HASHTAGS.length ) {952 if ( hashtags[i] == STORED_HASHTAGS[j].name ) {953 STORED_HASHTAGS[j].count += 1;954 j+=1;955 break;956 } else {957 j += 1;958 }959 }960961 if ( j >= STORED_HASHTAGS.length ) break;962 else i += 1;963 }964 while ( i < hashtags.length ) {965 STORED_HASHTAGS.push({966 name: hashtags[i],967 count: 1,968 });969 i += 1;hashtags970 }971 await AsyncStorage.setItem('HASHTAGS', JSON.stringify(STORED_HASHTAGS) );972 }973974 // Handles button press action to get hashtag suggestions975 _handleHashtagGETButton = async () => {976 const {tags, caption} = this.state;977 let hashtags = caption.match(/#[\p{L}]+/ugi) || []978 tags.sort( (a,b) => a.value < b.value ? -1 : 1);979 hashtags.sort( (a,b) => a.value < b.value ? -1 : 1);980981 console.log(tags, hashtags);982983 for ( let i in tags ) {984 tags[i].selected = false;985 }986 for ( let v of hashtags ) {987 for ( let i in tags ) {988 console.log(v, '#'+tags[i].value )989 if ( v == '#'+tags[i].value ) {990 tags[i].selected = true;991 break;992 }993 }994 }995 console.log(tags);996 this.setState({ tags })997 };998999 render() {1000 return (1001 <>1002 {1003 (this.state.uploadStatusPayload.status) ? (1004 <UploadStatusModal1005 status={this.state.uploadStatusPayload.status}1006 currentQueue={this.state.uploadStatusPayload.currentQueue}1007 totalQueue={this.state.uploadStatusPayload.totalQueue}1008 uploadQueue={this.state.uploadStatusPayload.uploadQueue}1009 setMainPageState={payload => {1010 this.setState(payload);1011 }}1012 GoHome={() => {1013 StackActions.popToTop();1014 this.props.navigation.navigate('HOME');1015 }}1016 Close={() => {1017 this.setState({1018 uploadStatusPayload: {1019 status: '',1020 currentQueue: 0,1021 totalQueue: 0,1022 uploadQueue: [],1023 },1024 });1025 }}1026 TryAgain={(payload) => {1027 for (let [key, value] of Object.entries(payload)) {1028 this.state[key] = false;1029 }1030 console.log(this.state);1031 this._handleUpload();1032 }}1033 />1034 ) : null1035 }1036 <ScrollView1037 contentContainerStyle={{1038 backgroundColor: '#FFFFFF',1039 paddingHorizontal: GetWidth(17, 360),1040 paddingVertical: GetWidth(10, 360),1041 }}>10421043 <ImageView1044 images={this.state.image}1045 imageIndex={0}1046 isVisible={this.state.showImage}1047 onClose={() => this.setState({showImage: false})}1048 />1049 {this.state.Images.map((value, index) => (1050 <ImageCard1051 name={value.name}1052 path={value.uri}1053 key={index}1054 preview={() => this._handlePreview(value)}1055 remove={() => this._handleImageRemoveButton(value.uri)}1056 />1057 ))}1058 <TouchableOpacity1059 onPress={this._handleImageAdd}1060 style={{1061 height: GetHeight(61, 640),1062 borderWidth: 1,1063 borderColor: '#5859ED',1064 backgroundColor: '#FAFAFA',1065 borderStyle: 'dashed',1066 alignItems: 'center',1067 justifyContent: 'center',1068 borderRadius: 1,1069 marginVertical: 10,1070 }}>1071 <Text1072 style={{1073 fontSize: GetHeight(12, 640),1074 color: '#5859ED',1075 }}>1076 Select an image...1077 </Text>1078 </TouchableOpacity>1079 <TextInput1080 style={{1081 backgroundColor: 'white',1082 }}1083 mode="outlined"1084 placeholder="Write a caption..."1085 label={'Write a caption...'}1086 value={this.state.caption}1087 selectionColor={'#e0e0ff'}1088 numberOfLines={10}1089 multiline={true}1090 onChangeText={text => {1091 this._handleHashtagInput(text);1092 this.setState({caption: text});1093 }}1094 />10951096 <View1097 style={{1098 marginVertical: GetWidth(10, 360),1099 backgroundColor: '#e5e5e5',1100 padding: GetWidth(9, 360),1101 }}>1102 <View1103 style={{1104 flexDirection: 'row',1105 }}>1106 <TouchableOpacity1107 onPress={this._handleGETTags}1108 style={{1109 backgroundColor: '#5859ED',1110 alignItems: 'center',1111 justifyContent:"center",1112 width: GetWidth(78,360),1113 height: GetHeight(28, 640),1114 alignContent: 'center',1115 }}>1116 <Text1117 style={{1118 color: 'white',1119 fontSize: GetHeight(12, 640),1120 margin: GetHeight(6, 640),1121 }}>1122 Get Tags1123 </Text>1124 </TouchableOpacity>1125 <View style={{flex: 1, flexDirection: 'row-reverse'}}>1126 {this.state.pressGETTags ? (1127 <ActivityIndicator animating={true} color={'#5859ED'} />1128 ) : null}1129 </View>1130 </View>1131 {this.state.tags.length > 0 ? (1132 <View1133 style={{1134 flexWrap: 'wrap',1135 flexDirection: 'row',1136 }}>1137 {TagsCard(this.state.tags, this._handlePushCaption, this._handleHashtagButtonPress)}1138 </View>1139 ) : null}1140 </View>11411142 <View1143 style={{1144 padding: GetWidth(17, 360),1145 }}>1146 <Text1147 style={{1148 fontWeight: 'bold',1149 fontSize: GetHeight(13, 640),1150 }}>1151 Post to:1152 </Text>1153 <View style={{height: GetHeight(10, 640)}} />1154 <View1155 style={{1156 flexDirection: 'row',1157 alignItems: 'stretch',1158 justifyContent: 'space-around',1159 }}>1160 <View1161 style={{1162 flex: 1,1163 flexDirection: 'row',1164 }}>1165 <View1166 style={{1167 padding: GetHeight(7, 640),1168 }}>1169 <Icon name={'facebook-square'} size={GetHeight(17, 640)} />1170 </View>1171 <View1172 style={{1173 justifyContent: 'center',1174 paddingBottom: GetHeight(8, 640),1175 }}>1176 <Text1177 style={{1178 fontSize: GetHeight(12, 640),1179 }}>1180 Facebook1181 </Text>1182 </View>1183 </View>1184 <View1185 style={{1186 flex: 1,1187 justifyContent: 'center',1188 paddingBottom: GetHeight(8, 640),1189 }}>1190 <Switch1191 disabled={!this.state.facebookPageAccessToken}1192 color={'#5859ED'}1193 style={{1194 paddingBottom: 10,1195 }}1196 value={this.state.facebookPublish}1197 onValueChange={() =>1198 this.setState({1199 facebookPublish: !this.state.facebookPublish,1200 })1201 }1202 />1203 </View>1204 </View>1205 <View1206 style={{1207 flexDirection: 'row',1208 alignItems: 'stretch',1209 justifyContent: 'space-around',1210 }}>1211 <View1212 style={{1213 flex: 1,1214 flexDirection: 'row',1215 }}>1216 <View1217 style={{1218 padding: GetHeight(7, 640),1219 }}>1220 <Icon name={'linkedin-square'} size={GetHeight(17, 640)} />1221 </View>1222 <View1223 style={{1224 justifyContent: 'center',1225 paddingBottom: GetHeight(8, 640),1226 }}>1227 <Text1228 style={{1229 fontSize: GetHeight(12, 640),1230 }}>1231 Linkedin1232 </Text>1233 </View>1234 </View>1235 <View1236 style={{1237 flex: 1,1238 justifyContent: 'center',1239 paddingBottom: GetHeight(8, 640),1240 alignSelf: 'center',1241 }}>1242 <Switch1243 disabled={!this.state.linkedinAccessToken}1244 style={{1245 paddingBottom: 10,1246 }}1247 color={'#5859ED'}1248 value={this.state.linkedinPublish}1249 onValueChange={() =>1250 this.setState({1251 linkedinPublish: !this.state.linkedinPublish,1252 })1253 }1254 />1255 </View>1256 </View>1257 <View1258 style={{1259 flexDirection: 'row',1260 alignItems: 'stretch',1261 justifyContent: 'space-around',1262 }}>1263 <View1264 style={{1265 flex: 1,1266 flexDirection: 'row',1267 }}>1268 <View1269 style={{1270 padding: GetHeight(7, 640),1271 }}>1272 <Icon name={'twitter'} size={GetHeight(17, 640)} />1273 </View>1274 <View1275 style={{1276 justifyContent: 'center',1277 paddingBottom: GetHeight(8, 640),1278 }}>1279 <Text1280 style={{1281 fontSize: GetHeight(12, 640),1282 }}>1283 Twitter1284 </Text>1285 </View>1286 </View>1287 <View1288 style={{1289 flex: 1,1290 justifyContent: 'center',1291 paddingBottom: GetHeight(8, 640),1292 }}>1293 <Switch1294 disabled={!this.state.twitterAccessTokenSecret}1295 style={{1296 paddingBottom: 10,1297 }}1298 color={'#5859ED'}1299 value={this.state.twitterPublish}1300 onValueChange={() =>1301 this.setState({1302 twitterPublish: !this.state.twitterPublish,1303 })1304 }1305 />1306 </View>1307 </View>1308 </View>1309 <View>1310 <Button1311 onPress={this._handleUpload}1312 mode={'contained'}1313 color={'#5859ED'}1314 uppercase={false}1315 style={{1316 alignItems: 'center',1317 borderRadius: 0,1318 height: GetHeight(41, 640),1319 elevation: 0,1320 }}1321 contentStyle={{1322 height: GetHeight(41, 640),1323 width: GetWidth(303, 360),1324 }}1325 labelStyle={{1326 fontSize: GetHeight(14, 640),1327 }}>1328 Upload1329 </Button>1330 </View>1331 </ScrollView>1332 </>1333 );1334 }13351336 // Handles Upload button press action1337 _handleUpload = async () => {1338 this.AddHashtagsToStore();1339 // Requires state parameters13401341 let {1342 facebookPublish,1343 twitterPublish,1344 linkedinPublish,1345 caption,1346 Images,1347 } = this.state;13481349 // Parameters for upload prompt13501351 let totalQueue = 0;1352 let currentQueue = 0;13531354 // Required Checks13551356 if (caption.length == 0) {1357 Alert.alert('Attention', 'Caption is empty');1358 return;1359 }1360 if (Images.length == 0) {1361 Alert.alert('Attention', 'No images added');1362 return;1363 }13641365 // Updating parameters13661367 if (facebookPublish) {1368 totalQueue += 1;1369 }1370 if (twitterPublish) {1371 totalQueue += 1;1372 }1373 if (linkedinPublish) {1374 totalQueue += 1;1375 }13761377 // Updating the state1378 // Will cause the upload status prompt to open1379 const updateCurrentState = () => {1380 this.setState({1381 uploadStatusPayload: {1382 status: 'wait',1383 currentQueue,1384 totalQueue,1385 uploadQueue: [],1386 },1387 });1388 };1389 updateCurrentState();13901391 // Upload status flags13921393 let facebookStatus, twitterStatus, linkedinStatus;13941395 // final status flag13961397 let finalStatus = 0;13981399 // Upload Queue Array14001401 let UploadQueue = [];14021403 if (facebookPublish) {1404 try {1405 facebookStatus = await UploadToFacebook(Images, caption);1406 } catch (e) {1407 facebookStatus = e;1408 }1409 UploadQueue.push({1410 name: 'facebook',1411 icon: 'facebook-square',1412 status: facebookStatus,1413 });1414 finalStatus = finalStatus || facebookStatus.status;1415 currentQueue += 1;1416 updateCurrentState();1417 }1418 if (twitterPublish) {1419 try {1420 twitterStatus = await handleTwitterUpload(Images, caption);1421 } catch (e) {1422 twitterStatus = e;1423 }1424 UploadQueue.push({1425 name: 'twitter',1426 icon: 'twitter',1427 status: twitterStatus,1428 });1429 finalStatus = finalStatus || twitterStatus.status;1430 currentQueue += 1;1431 updateCurrentState();1432 }1433 if (linkedinPublish) {1434 try {1435 linkedinStatus = await handleLinkedinUpload(Images, caption);1436 } catch (e) {1437 linkedinStatus = e;1438 }1439 UploadQueue.push({1440 name: 'linkedin',1441 icon: 'linkedin-square',1442 status: linkedinStatus,1443 });1444 finalStatus = finalStatus || linkedinStatus.status;1445 currentQueue += 1;1446 updateCurrentState();1447 }14481449 const state = finalStatus == 0 ? 'success' : 'error';1450 this.setState({1451 uploadStatusPayload: {1452 status: state,1453 currentQueue,1454 totalQueue,1455 uploadQueue: UploadQueue,1456 },1457 });1458 }; ...

Full Screen

Full Screen

VBox.js

Source:VBox.js Github

copy

Full Screen

...19 }20 function getWidth(index) {21 return ct.items.getAt(index).element.getWidth();22 }23 function getHeight(index) {24 return ct.items.getAt(index).element.getHeight();25 }26 afterEach(function(){27 ct = c = Ext.destroy(ct, c);28 });29 30 describe("defaults", function() {31 var layout;32 beforeEach(function() {33 ct = new Ext.container.Container({34 renderTo: Ext.getBody(),35 layout: 'vbox',36 width: 100,37 height: 10038 });39 layout = ct.getLayout();40 });41 afterEach(function() {42 layout = null;43 });44 45 it("should have align: stretch", function() {46 expect(layout.getAlign()).toBe('stretch');47 });48 it("should have constrainAlign: false", function () {49 expect(layout.getConstrainAlign()).toBe(false);50 });51 52 it("should have pack start", function() {53 expect(layout.getPack()).toBe('start');54 }); 55 });56 describe('sizes as percentages', function () {57 it('should correctly size items using percentages', function () {58 ct = Ext.widget({59 xtype: 'container',60 layout: {61 type: 'vbox',62 align: 'start'63 },64 height: 300,65 width: 200,66 renderTo: Ext.getBody(),67 autoSize: Ext.supports.PercentageSizeFlexBug ? false : null,68 items: [{69 xtype: 'component',70 height: '20%',71 width: 10072 }, {73 xtype: 'component',74 height: 30,75 width: '75%'76 }, {77 xtype: 'component',78 flex: 1,79 width: '100%'80 }, {81 xtype: 'component',82 flex: 2,83 html: '<div style="width:50px"></div>'84 }]85 });86 expect(ct).toHaveLayout({87 el: {w: 200, h: 300},88 items: {89 0: {el: {xywh: '0 0 100 60'}},90 1: {el: {xywh: '0 60 150 30'}},91 2: {el: {xywh: '0 90 200 70'}},92 3: {el: {xywh: '0 160 50 140'}}93 }94 });95 });96 });97 it("should apply margin to components", function(){98 ct = new Ext.container.Container({99 width: 200,100 height: 200,101 renderTo: Ext.getBody(),102 defaultType: 'component',103 layout: {104 type: 'vbox',105 align: 'stretch'106 },107 defaults: {108 flex: 1,109 margin: 5110 },111 items: [{}, {}]112 }); 113 114 expect(getY(0)).toBe(5);115 expect(getX(0)).toBe(5);116 117 expect(getY(1)).toBe(105);118 expect(getX(1)).toBe(5);119 });120 121 describe("pack", function(){122 function makeCt(pack, cfg) {123 ct = new Ext.container.Container(Ext.apply({124 defaultType: 'component',125 renderTo: Ext.getBody(),126 width: 600,127 height: 600,128 layout: {129 type: 'vbox',130 pack: pack131 },132 items: [{133 height: 30134 }, {135 height: 40136 }, {137 height: 20138 }]139 }, cfg));140 }141 142 function getY(index) {143 return ct.items.getAt(index).el.getY(); 144 }145 146 it("should pack at the top with pack: start", function(){147 makeCt('start');148 expect(getY(0)).toBe(0);149 expect(getY(1)).toBe(30);150 expect(getY(2)).toBe(70);151 });152 153 it("should pack in the middle with pack: center", function(){154 makeCt('center');155 expect(getY(0)).toBe(255);156 expect(getY(1)).toBe(285);157 expect(getY(2)).toBe(325);158 });159 160 it("should pack at the bottom with pack: cend", function(){161 makeCt('end');162 expect(getY(0)).toBe(510);163 expect(getY(1)).toBe(540);164 expect(getY(2)).toBe(580);165 });166 it("should pack: justify", function () {167 makeCt('justify');168 expect(getY(0)).toBe(0);169 expect(getY(1)).toBe(285);170 expect(getY(2)).toBe(580);171 });172 it("should pack: space-between", function () {173 makeCt('space-between');174 expect(getY(0)).toBe(0);175 expect(getY(1)).toBe(285);176 expect(getY(2)).toBe(580);177 });178 it("should pack: space-around", function () {179 makeCt('space-around');180 expect(getY(0)).toBe(85);181 expect(getY(1)).toBe(285);182 expect(getY(2)).toBe(495);183 });184 it("should pack start with maxHeighted items", function () {185 // https://sencha.jira.com/browse/EXTJS-25260186 makeCt('start', {187 // These items must not have a "height", only a "maxHeight"188 items: [{189 flex: 1,190 maxHeight: 100191 }, {192 flex: 1,193 maxHeight: 100194 }, {195 flex: 1,196 maxHeight: 100197 }]198 });199 expect(getY(0)).toBe(0);200 expect(getY(1)).toBe(100);201 expect(getY(2)).toBe(200);202 expect(getHeight(0)).toBe(100);203 expect(getHeight(1)).toBe(100);204 expect(getHeight(2)).toBe(100);205 });206 it("should pack center with maxHeighted items", function () {207 // https://sencha.jira.com/browse/EXTJS-25260208 makeCt('center', {209 // These items must not have a "height", only a "maxHeight"210 items: [{211 flex: 1,212 maxHeight: 100213 }, {214 flex: 1,215 maxHeight: 100216 }, {217 flex: 1,218 maxHeight: 100219 }]220 });221 expect(getY(0)).toBe(150);222 expect(getY(1)).toBe(250);223 expect(getY(2)).toBe(350);224 expect(getHeight(0)).toBe(100);225 expect(getHeight(1)).toBe(100);226 expect(getHeight(2)).toBe(100);227 });228 it("should pack end with maxHeighted items", function () {229 // https://sencha.jira.com/browse/EXTJS-25260230 makeCt('end', {231 // These items must not have a "height", only a "maxHeight"232 items: [{233 flex: 1,234 maxHeight: 100235 }, {236 flex: 1,237 maxHeight: 100238 }, {239 flex: 1,240 maxHeight: 100241 }]242 });243 expect(getY(0)).toBe(300);244 expect(getY(1)).toBe(400);245 expect(getY(2)).toBe(500);246 expect(getHeight(0)).toBe(100);247 expect(getHeight(1)).toBe(100);248 expect(getHeight(2)).toBe(100);249 });250 });251 describe("reverse", function() {252 function makeCt (reverse){253 ct = new Ext.container.Container({254 defaultType: 'component',255 renderTo: Ext.getBody(),256 width: 600,257 height: 600,258 layout: {259 type: 'vbox',260 reverse: reverse261 },262 items: [{263 flex: 1264 }, {265 flex: 1266 }, {267 flex: 1268 }]269 });270 }271 it("should not reverse with false", function() {272 makeCt(false);273 expect(getY(0)).toBe(0);274 expect(getY(1)).toBe(200);275 expect(getY(2)).toBe(400);276 });277 it("should reverse with true", function() {278 makeCt(true);279 expect(getY(2)).toBe(0);280 expect(getY(1)).toBe(200);281 expect(getY(0)).toBe(400);282 });283 });284 285 describe("align", function(){286 function makeCt(align, items, options) {287 options = options || {};288 ct = new Ext.container.Container({289 defaultType: 'component',290 renderTo: options.floated ? null : Ext.getBody(),291 width: ('width' in options) ? options.width : 600,292 height: ('height' in options) ? options.height : 600,293 autoScroll: !!options.autoScroll,294 floated: options.floated || null,295 hidden: false,296 autoSize: (options.autoSize != null) ? options.autoSize : null,297 layout: {298 type: 'vbox',299 align: align,300 constrainAlign: !!options.constrainAlign301 },302 items: items303 });304 }305 306 describe("left/center/right", function() {307 308 it("should keep items at the left when using align: start", function(){309 makeCt('start', [{310 html: '<div style="width: 20px"></div>'311 }, {312 html: '<div style="width: 40px"></div>'313 }]);314 expect(getX(0)).toBe(0);315 expect(getX(1)).toBe(0);316 });317 318 it("should align items in the middle when using align: center", function(){319 makeCt('center', [{320 width: 100 321 }, {322 width: 300323 }]); 324 expect(getX(0)).toBe(250);325 expect(getX(1)).toBe(150);326 });327 328 it("should keep items to the right when using align: end", function(){329 makeCt('end', [{330 html: '<div style="width: 20px"></div>'331 }, {332 html: '<div style="width: 40px"></div>'333 }]);334 expect(getX(0)).toBe(600 - getWidth(0));335 expect(getX(1)).toBe(600 - getWidth(1));336 });337 338 describe("constrainAlign", function(){339 function makeLongString(c, len) {340 var out = [],341 i = 0;342 343 for (; i < len; ++i) {344 out.push(c);345 }346 return out.join(' ');347 }348 349 it("should constrain a shrink wrapped item with align: left", function(){350 makeCt('left', [{351 html: makeLongString('A', 100)352 }], {353 constrainAlign: true,354 autoSize: Ext.supports.PercentageSizeFlexBug ? false : null355 });356 expect(getWidth(0)).toBe(600);357 expect(getX(0)).toBe(0);358 });359 360 it("should constrain a shrink wrapped item with align: center", function(){361 makeCt('center', [{362 html: makeLongString('A', 100)363 }], {364 constrainAlign: true,365 autoSize: Ext.supports.PercentageSizeFlexBug ? false : null366 });367 expect(getWidth(0)).toBe(600);368 expect(getX(0)).toBe(0);369 });370 371 it("should constrain a shrink wrapped item with align: right", function(){372 makeCt('center', [{373 html: makeLongString('A', 100)374 }], {375 constrainAlign: true,376 autoSize: Ext.supports.PercentageSizeFlexBug ? false : null377 });378 expect(getWidth(0)).toBe(600);379 expect(getX(0)).toBe(0);380 });381 382 it("should not constrain a fixed width item", function(){383 makeCt('left', [{384 html: 'A',385 width: 1000386 }], {387 constrainAlign: false,388 autoSize: Ext.supports.PercentageSizeFlexBug ? false : null389 });390 expect(getWidth(0)).toBe(1000);391 });392 393 it("should recalculate the top positions", function(){394 makeCt('left', [{395 html: makeLongString('A', 100)396 }, {397 html: 'B'398 }], {399 constrainAlign: true,400 autoSize: Ext.supports.PercentageSizeFlexBug ? false : null401 });402 403 expect(getY(0)).toBe(0);404 expect(getY(1)).toBe(getHeight(0)); 405 });406 });407 });408 409 describe("stretch", function() {410 411 it("should stretch all items to the size of the largest when using align: stretch", function(){412 makeCt('stretch', [{413 html: 'foo'414 }, {415 html: 'foo bar baz'416 }, {417 html: 'foo'418 }], { width: null, floated: true });419 420 c = new Ext.Component({421 html: 'foo bar baz',422 floated: true,423 hidden: false424 });425 var expected = c.element.getWidth();426 c.destroy();427 expect(getWidth(0)).toBe(expected);428 expect(getWidth(1)).toBe(expected);429 expect(getWidth(2)).toBe(expected);430 });431 432 it("should always use a fixed width over stretch", function(){433 makeCt('stretch', [{434 width: 30435 }, {436 html: 'foo bar baz blah long text'437 }, {438 html: 'foo'439 }]);440 441 expect(getWidth(0)).toBe(30);442 expect(getWidth(1)).toBe(600);443 expect(getWidth(2)).toBe(600);444 });445 446 describe("minWidth", function() {447 it("should stretch an item with a minWidth", function(){448 makeCt('stretch', [{449 width: 30450 }, {451 minWidth: 5452 }]);453 expect(getWidth(0)).toBe(30);454 expect(getWidth(1)).toBe(600);455 });456 457 it("should stretch to the item with the largest minWidth", function(){458 makeCt('stretch', [{459 minWidth: 30460 }, {461 minWidth: 50462 }], { width: null, floated: true });463 expect(getWidth(0)).toBe(50);464 expect(getWidth(1)).toBe(50);465 });466 467 it("should stretch a single item outside the bounds of the container", function(){468 makeCt('stretch', [{469 minWidth: 1000,470 html: 'Content...'471 }], {472 scrollable: true473 });474 expect(getWidth(0)).toBe(1000);475 });476 });477 478 it("should respect a maxWidth", function(){479 makeCt('stretch', [{480 width: 30481 }, {482 maxWidth: 20483 }]);484 expect(getWidth(0)).toBe(30);485 expect(getWidth(1)).toBe(20);486 });487 });488 489 it("should stretch all items to the container width", function(){490 makeCt('stretch', [{491 }, {492 }]);493 expect(getWidth(0)).toBe(600);494 expect(getWidth(1)).toBe(600);495 });496 });497 498 describe("height", function(){499 function makeCt(items, options) {500 options = options || {};501 ct = new Ext.container.Container({502 renderTo: Ext.getBody(),503 width: 100,504 height: 600,505 defaultType: 'component',506 autoSize: (options.autoSize != null) ? options.autoSize : null,507 layout: {508 type: 'vbox',509 align: 'stretch'510 },511 items: items512 });513 }514 describe("flex only", function(){515 it("should stretch a single flex item to the height of the container", function(){516 makeCt({517 flex: 1518 });519 expect(getHeight(0)).toBe(600);520 });521 522 it("should stretch 3 equally flexed items equally", function(){523 makeCt([{524 flex: 1525 }, {526 flex: 1 527 }, {528 flex: 1529 }]);530 expect(getHeight(0)).toBe(200);531 expect(getHeight(1)).toBe(200);532 expect(getHeight(2)).toBe(200);533 });534 535 it("should flex 2 items according to ratio", function(){536 makeCt([{537 flex: 3 538 }, {539 flex: 1540 }]);541 expect(getHeight(0)).toBe(450);542 expect(getHeight(1)).toBe(150);543 });544 545 it("should flex 4 items according to ratio", function(){546 makeCt([{547 flex: 3 548 }, {549 flex: 1550 }, {551 flex: 3552 }, {553 flex: 1554 }]);555 expect(getHeight(0)).toBe(225);556 expect(getHeight(1)).toBe(75);557 expect(getHeight(2)).toBe(225);558 expect(getHeight(3)).toBe(75);559 });560 561 it("should use flex as a ratio", function(){562 makeCt([{563 flex: 4564 }, {565 flex: 2566 }]);567 expect(getHeight(0)).toBe(400);568 expect(getHeight(1)).toBe(200);569 });570 });571 572 describe("fixed height only", function(){573 it("should set the height of a single item", function(){574 makeCt({575 height: 200576 }); 577 expect(getHeight(0)).toBe(200);578 });579 580 it("should set the height of multiple items", function(){581 makeCt([{582 height: 500583 }, {584 height: 50585 }]); 586 expect(getHeight(0)).toBe(500);587 expect(getHeight(1)).toBe(50);588 });589 590 it("should allow a single item to exceed the container height", function(){591 makeCt({592 height: 900593 });594 expect(getHeight(0)).toBe(900);595 });596 (hasWebkitHeightConstraintBug ? xit : it)("should not allow a single item with shrink: 1 to exceed the container height", function(){597 makeCt({598 height: 900,599 flex: {600 shrink: 1601 }602 });603 expect(getHeight(0)).toBe(600);604 });605 it("should allow multiple items to exceed the container height", function(){606 makeCt([{607 height: 400608 }, {609 height: 400610 }]);611 expect(getHeight(0)).toBe(400);612 expect(getHeight(1)).toBe(400);613 });614 (hasWebkitHeightConstraintBug ? xit : it)("should not allow multiple items with shrink: 1 to exceed the container height", function(){615 makeCt([{616 height: 400,617 flex: {618 shrink: 1619 }620 }, {621 height: 400,622 flex: {623 shrink: 1624 }625 }]);626 expect(getHeight(0)).toBe(300);627 expect(getHeight(1)).toBe(300);628 });629 });630 describe("%age", function(){631 it("should be able to use %age height", function(){632 makeCt([{633 height: '50%'634 }, {635 height: '50%'636 }], {637 autoSize: Ext.supports.PercentageSizeFlexBug ? false : null638 });639 expect(getHeight(0)).toBe(300);640 expect(getHeight(1)).toBe(300);641 });642 643 it("should work with fixed height", function(){644 makeCt([{645 height: 100646 }, {647 height: '20%'648 }, {649 height: 380650 }], {651 autoSize: Ext.supports.PercentageSizeFlexBug ? false : null652 });653 expect(getHeight(0)).toBe(100);654 expect(getHeight(1)).toBe(120);655 expect(getHeight(2)).toBe(380);656 });657 658 it("should work with flex", function(){659 makeCt([{660 flex: 2661 }, {662 height: '40%'663 }, {664 flex: 1665 }], {666 autoSize: Ext.supports.PercentageSizeFlexBug ? false : null667 });668 expect(getHeight(0)).toBe(240);669 expect(getHeight(1)).toBe(240);670 expect(getHeight(2)).toBe(120);671 });672 });673 674 describe("mixed", function(){675 it("should give any remaining space to a single flexed item", function(){676 makeCt([{677 height: 200678 }, {679 flex: 1680 }]);681 expect(getHeight(0)).toBe(200);682 expect(getHeight(1)).toBe(400);683 });684 685 it("should flex a single item with 2 fixed", function(){686 makeCt([{687 height: 100688 }, {689 flex: 1690 }, {691 height: 300692 }]);693 expect(getHeight(0)).toBe(100);694 expect(getHeight(1)).toBe(200);695 expect(getHeight(2)).toBe(300);696 });697 698 it("should flex 2 items with 1 fixed", function(){699 makeCt([{700 flex: 2701 }, {702 height: 300703 }, {704 flex: 1705 }]); 706 expect(getHeight(0)).toBe(200);707 expect(getHeight(1)).toBe(300);708 expect(getHeight(2)).toBe(100);709 });710 it("should give priority to flex over a fixed height", function(){711 makeCt([{712 flex: 1,713 height: 200714 }, {715 flex: 1716 }]);717 expect(getHeight(0)).toBe(300);718 expect(getHeight(1)).toBe(300);719 });720 });721 describe("min/max", function(){722 it("should assign a 0 height if there is no more flex height", function(){723 makeCt([{724 flex: 1,725 style: 'line-height:0'726 }, {727 height: 700728 }]);729 expect(getHeight(0)).toBe(0);730 expect(getHeight(1)).toBe(700);731 });732 733 it("should respect a minWidth on a flex even if there is no more flex width", function(){734 makeCt([{735 flex: 1,736 minHeight: 50737 }, {738 height: 700739 }]);740 expect(getHeight(0)).toBe(50);741 expect(getHeight(1)).toBe(700);742 });743 744 it("should respect a minWidth on a flex even if there is no excess flex width", function(){745 makeCt([{746 flex: 1,747 maxHeight: 100748 }, {749 height: 300750 }]);751 expect(getHeight(0)).toBe(100);752 expect(getHeight(1)).toBe(300); 753 });754 // Disabled in IE11 because it computes flex values incorrectly when using min-height755 (Ext.isIE11 ? xit: it)("should update flex values based on min constraint", function(){756 var c1 = new Ext.Component({757 flex: 1,758 minHeight: 500759 }), c2 = new Ext.Component({760 flex: 1761 });762 makeCt([c1, c2]);763 expect(c1.el.getHeight()).toBe(500);764 expect(c2.el.getHeight()).toBe(100);765 });766 // Disabled in IE11 because it computes flex values incorrectly when using min-height767 (Ext.isIE11 ? xit: it)("should handle multiple min constraints", function(){768 var c1 = new Ext.Component({769 flex: 1,770 minHeight: 250771 }), c2 = new Ext.Component({772 flex: 1,773 minHeight: 250774 }), c3 = new Ext.Component({775 flex: 1776 });777 778 makeCt([c1, c2, c3]);779 expect(c1.el.getHeight()).toBe(250);780 expect(c2.el.getHeight()).toBe(250);781 expect(c3.el.getHeight()).toBe(100);782 });783 784 it("should update flex values based on max constraint", function(){785 var c1 = new Ext.Component({786 flex: 1,787 maxHeight: 100788 }), c2 = new Ext.Component({789 flex: 1790 });791 makeCt([c1, c2]);792 expect(c1.el.getHeight()).toBe(100);793 expect(c2.el.getHeight()).toBe(500);794 });795 796 it("should update flex values based on multiple max constraints", function(){797 var c1 = new Ext.Component({798 flex: 1,799 maxHeight: 100800 }), c2 = new Ext.Component({801 flex: 1,802 maxHeight: 100803 }), c3 = new Ext.Component({804 flex: 1805 });806 makeCt([c1, c2, c3]);807 expect(c1.el.getHeight()).toBe(100);808 expect(c2.el.getHeight()).toBe(100);809 expect(c3.el.getHeight()).toBe(400);810 });811 it("should give precedence to min constraints over flex when the min is the same", function() {812 var c1 = new Ext.Component({813 flex: 1,814 minHeight: 200815 }), c2 = new Ext.Component({816 flex: 3,817 minHeight: 200818 }), c3 = new Ext.Component({819 flex: 1,820 minHeight: 200821 });822 makeCt([c1, c2, c3]);823 expect(c1.el.getHeight()).toBe(200);824 expect(c2.el.getHeight()).toBe(200);825 expect(c3.el.getHeight()).toBe(200);826 });827 it("should give precedence to max constraints over flex when the max is the same", function() {828 var c1 = new Ext.Component({829 flex: 1,830 maxHeight: 100831 }), c2 = new Ext.Component({832 flex: 3,833 maxHeight: 100834 }), c3 = new Ext.Component({835 flex: 1,836 maxHeight: 100837 });838 makeCt([c1, c2, c3]);839 expect(c1.el.getHeight()).toBe(100);840 expect(c2.el.getHeight()).toBe(100);841 expect(c3.el.getHeight()).toBe(100);842 });843 describe("with %age", function() {844 it("should respect min constraints", function() {845 document.documentElement.style.height = document.body.style.height = '100%';846 makeCt([{847 height: '10%',848 minHeight: 250849 },{850 flex: 1851 }]);852 expect(getHeight(0)).toBe(250);853 expect(getHeight(1)).toBe(350);854 document.documentElement.style.height = document.body.style.height = '';855 });856 it("should respect max constraints", function() {857 document.documentElement.style.height = document.body.style.height = '100%';858 makeCt([{859 height: '90%',860 maxHeight: 100861 },{862 flex: 1863 }], {864 autoSize: Ext.supports.PercentageSizeFlexBug ? false : null865 });866 expect(getHeight(0)).toBe(100);867 expect(getHeight(1)).toBe(500);868 document.documentElement.style.height = document.body.style.height = '';869 });870 });871 });872 describe("flex config parsing", function () {873 var item;874 function makeFlex(flex) {875 ct = new Ext.Container({876 renderTo: Ext.getBody(),877 layout: 'vbox',878 items: [{879 xtype: 'component',880 flex: flex || null881 }]...

Full Screen

Full Screen

learnStart.js

Source:learnStart.js Github

copy

Full Screen

...145 switch (item.item.name) {146 case 'visa':147 return (148 <TouchableOpacity style={styles.listItem} onPress={() => this._editPayment(item.item)}>149 <Image style={{width: getWidth(24), height: getHeight(16), marginLeft: getWidth(24), marginRight: getWidth(16)}}150 resizeMode={'contain'} source={VISA_IMAGE}151 />152 <Text style={styles.listText}>153 {'Visa, ' + item.item.number}154 </Text>155 </TouchableOpacity>156 )157 case 'mastercard': 158 return (159 <TouchableOpacity style={styles.listItem} onPress={() => this._editPayment(item.item)}>160 <Image style={{width: getWidth(24), height: getHeight(16), marginLeft: getWidth(24), marginRight: getWidth(16)}}161 resizeMode={'contain'} source={MASTER_IMAGE}162 />163 <Text style={styles.listText}>164 {'Mastercard, ' + item.item.number}165 </Text>166 </TouchableOpacity>167 )168 case 'amex':169 return (170 <TouchableOpacity style={styles.listItem} onPress={() => this._editPayment(item.item)}>171 <Image style={{width: getWidth(24), height: getHeight(30), marginLeft: getWidth(24), marginRight: getWidth(16)}}172 resizeMode={'contain'} source={AMEX_IMAGE}173 />174 <Text style={styles.listText}>175 {'American Express, ' + item.item.number}176 </Text>177 </TouchableOpacity>178 )179 case 'discover': 180 return (181 <TouchableOpacity style={styles.listItem} onPress={() => this._editPayment(item.item)}>182 <Image style={{width: getWidth(20), height: getHeight(24), marginLeft: getWidth(24), marginRight: getWidth(16)}}183 resizeMode={'contain'} source={DISCOVER_IMAGE}184 />185 <Text style={styles.listText}>186 {'Discover, ' + item.item.number}187 </Text>188 </TouchableOpacity>189 )190 case 'diners':191 return (192 <TouchableOpacity style={styles.listItem} onPress={() => this._editPayment(item.item)}>193 <Image style={{width: getWidth(20), height: getHeight(24), marginLeft: getWidth(24), marginRight: getWidth(16)}}194 resizeMode={'contain'} source={DINERS_IMAGE}195 />196 <Text style={styles.listText}>197 {'Diners Club, ' + item.item.number}198 </Text>199 </TouchableOpacity>200 )201 case 'jcb':202 return (203 <TouchableOpacity style={styles.listItem} onPress={() => this._editPayment(item.item)}>204 <Image style={{width: getWidth(20), height: getHeight(24), marginLeft: getWidth(24), marginRight: getWidth(16)}}205 resizeMode={'contain'} source={JCB_IMAGE}206 />207 <Text style={styles.listText}>208 {'JCB, ' + item.item.number}209 </Text>210 </TouchableOpacity>211 )212 }213 }214 _editPayment = (paymentMethod) => {215 firestore.collection('users').doc(auth.currentUser.uid).update({216 default_paymentMethod: paymentMethod.id217 }).then((value) => {218 this.setState({modalVisible: false, currentNumber: paymentMethod.number});219 switch (paymentMethod.name) {220 case 'visa':221 this.setState({currentImage: VISA_IMAGE});222 break;223 case 'mastercard':224 this.setState({currentImage: MASTER_IMAGE});225 break;226 case 'amex': 227 this.setState({currentImage: AMEX_IMAGE});228 break;229 case 'discover':230 this.setState({currentImage: DISCOVER_IMAGE});231 break;232 case 'diners':233 this.setState({currentImage: DINERS_IMAGE});234 break;235 case 'jcb':236 this.setState({currentImage: JCB_IMAGE});237 break;238 default:239 this.setState({currentImage: DINERS_IMAGE});240 break;241 }242 }).catch(() => {243 this.setState({modalVisible: false});244 })245 }246 componentDidMount() {247 firestore.collection('users').doc(auth.currentUser.uid).update({248 default_paymentMethod: this.state.firstPayment.id249 }).then((value) => {250 251 switch (this.state.firstPayment.name) {252 case 'visa':253 this.setState({currentImage: VISA_IMAGE});254 break;255 case 'mastercard':256 this.setState({currentImage: MASTER_IMAGE});257 break;258 case 'amex': 259 this.setState({currentImage: AMEX_IMAGE});260 break;261 case 'discover':262 this.setState({currentImage: DISCOVER_IMAGE});263 break;264 case 'diners':265 this.setState({currentImage: DINERS_IMAGE});266 break;267 case 'jcb':268 this.setState({currentImage: JCB_IMAGE});269 break;270 default:271 this.setState({currentImage: DINERS_IMAGE});272 break;273 }274 }).catch(() => {275 })276 }277 render () {278 const {sessionData} = this.props;279 console.log("Learn Start sessionData = ", sessionData);280 let userRating = sessionData.userData.rating ? sessionData.userData.rating : 0;281 return (282 <Page>283 <View style={styles.container} >284 <Image style={{width: getWidth(155), height: getHeight(82)}} resizeMode={'contain'} source={ICON_LOGO}/>285 <View style={styles.modal}>286 <View style={{flex: 1, width: '100%', justifyContent: 'center', alignItems: 'center'}}>287 <Text style={styles.bodyText}>{this.props.sessionData.name}</Text>288 <View style={{flexDirection: 'row', justifyContent: 'center', alignItems: 'center'}}>289 {290 userRating > 0 ?291 <Star width={getWidth(28)} height={getHeight(27)} color ={PURPLE_MAIN}/>292 :293 <BStar width={getWidth(28)} height={getHeight(27)} color={'#FFFFFF'} stroke={BLACK_PRIMARY} />294 }295 {296 userRating > 1 ?297 <Star width={getWidth(28)} height={getHeight(27)} color ={PURPLE_MAIN}/>298 :299 <BStar width={getWidth(28)} height={getHeight(27)} color={'#FFFFFF'} stroke={BLACK_PRIMARY} /> 300 }301 {302 userRating > 2 ?303 <Star width={getWidth(28)} height={getHeight(27)} color ={PURPLE_MAIN}/>304 :305 <BStar width={getWidth(28)} height={getHeight(27)} color={'#FFFFFF'} stroke={BLACK_PRIMARY} /> 306 }307 {308 userRating > 3 ?309 <Star width={getWidth(28)} height={getHeight(27)} color ={PURPLE_MAIN}/>310 :311 <BStar width={getWidth(28)} height={getHeight(27)} color={'#FFFFFF'} stroke={BLACK_PRIMARY} /> 312 }313 {314 userRating > 4 ?315 <Star width={getWidth(28)} height={getHeight(27)} color ={PURPLE_MAIN}/>316 :317 <BStar width={getWidth(28)} height={getHeight(27)} color={'#FFFFFF'} stroke={BLACK_PRIMARY} /> 318 }319 </View>320 <Text style={styles.bodySecText}>321 {this.props.sessionData.phoneNumber}322 </Text>323 {/* <Text style={styles.bodyThirdText}>324 $0.00325 </Text> */}326 </View>327 {/* <TouchableOpacity style={styles.btnBody}328 onPress={this._gotoPayments}329 >330 <Text style={styles.btnText}>Home</Text>331 <View style={{flexDirection: 'row', alignItems: 'center'}}>332 {333 334 }335 <Image style={{width: getWidth(24), height: getHeight(15.87)}} source={this.state.currentImage}/>336 <Text style={styles.btnText}>{this.state.currentNumber}</Text>337 </View>338 <Text style={styles.btnText}>339 Change340 </Text>341 </TouchableOpacity> */}342 </View>343 <BaseButton 344 text={'LEARN'}345 onClick={this._goLearn}346 buttonStyle={{marginTop: getHeight(113)}}347 />348 <BaseButton 349 text={'CANCEL'}350 onClick={this._cancelLearn}351 buttonStyle={{marginTop: getHeight(22)}}352 />353 </View>354 {355 this.state.modalVisible == true ?356 <View style={{position: 'absolute', left: 0, top: 0, right: 0, bottom: 0, marginVertical: getHeight(100), marginHorizontal: getWidth(30), justifyContent: 'center', alginItems: 'center', backgroundColor: BLACK_PRIMARY, borderRadius: getHeight(10), paddingVertical: getHeight(10)}}>357 <FlatList 358 data={this.state.paymentData}359 renderItem={item => this._renderListItem(item)}360 keyExtractor={item => item.id}361 contentContainerStyle={{flex: 1, width: '100%'}}362 style={{flex: 1, width: '100%'}}363 />364 </View>365 : null366 }367 {368 this.state.warningVisible == true ?369 <View style={{flex: 1, width: '100%', justifyContent: 'center', alignItems: 'center', position: 'absolute', top: 0, left: 0, right: 0, bottom: 0}}>370 <View style={{width: getWidth(244), height: getHeight(262), backgroundColor: GRAY_SECONDARY, borderRadius: getHeight(10), alignItems: 'center'}}>371 <View style={{flex: 1, width: '100%', justifyContent: 'center', alignItems: 'center'}}>372 <Alert width={getWidth(44)} height={getHeight(38)} color={PURPLE_MAIN} />373 <Text style={{color: '#FFFFFF', fontFamily: 'Montserrat-Medium', fontSize: getHeight(18), marginTop: getHeight(29)}}>374 Please add the payment375 </Text>376 <Text style={{color: '#FFFFFF', fontFamily: 'Montserrat-Medium', fontSize: getHeight(18)}}>377 method to learn.378 </Text>379 </View>380 <TouchableOpacity style={{width: getWidth(220), height: getHeight(36), backgroundColor: '#FFFFFF', borderRadius: getHeight(10), marginBottom: getHeight(23), justifyContent: 'center', alignItems: 'center'}}381 onPress={() =>{this._addPayment()}}382 >383 <Text style={{color: PURPLE_MAIN, fontFamily: 'Montserrat-Medium', fontSize: getHeight(17)}}>OK</Text>384 </TouchableOpacity>385 </View>386 </View>387 : null388 }389 </Page>390 391 )392 }393};394LearnStart.navigatorStyle = {395 navBarHidden: true,396 statusBarBlur: false397};398const styles = StyleSheet.create({399 container: {400 flex: 1,401 justifyContent: 'center',402 alignItems: 'center'403 },404 loadText: {405 paddingBottom: getHeight(10),406 color: '#FFFFFF',407 fontFamily: 'Montserrat-Bold',408 },409 modal: {410 width: getWidth(244),411 height: getHeight(262),412 backgroundColor: '#FFFFFF',413 alignItems: 'center',414 borderRadius: getHeight(10),415 marginTop: getHeight(42)416 },417 btnText: {418 fontFamily: 'Montserrat-Medium',419 color: '#FFFFFF',420 fontSize: getHeight(18),421 marginLeft: getWidth(8)422 },423 bodyText: {424 fontFamily: 'Montserrat-Medium',425 fontSize: getHeight(20),426 color: BLACK_PRIMARY427 },428 bodySecText: {429 fontFamily: 'Montserrat-Medium',430 fontSize: getHeight(15),431 color: BLACK_PRIMARY,432 height: getHeight(20),433 paddingVertical: 0,434 marginTop: getHeight(5)435 },436 bodyThirdText: {437 fontFamily: 'Montserrat-Medium',438 fontSize: getHeight(18),439 color: BLACK_PRIMARY440 },441 btnBody: {442 width: getWidth(220), 443 height: getHeight(36), 444 borderRadius: getHeight(10), 445 backgroundColor: BLACK_PRIMARY, 446 justifyContent: 'space-between',447 alignItems: 'center', 448 flexDirection: 'row',449 paddingLeft: getWidth(13),450 paddingRight: getWidth(25),451 marginBottom: getHeight(23)452 },453 listText: {454 fontFamily: 'Montserrat-Medium',455 fontSize: getHeight(18),456 color: '#FFFFFF'457 },458 newListText: {459 fontFamily: 'Montserrat-Medium',460 fontSize: getHeight(18),461 color: GREEN_PRIMARY462 },463 listItem: {464 width: '100%', 465 height: getHeight(40), 466 flexDirection: 'row', 467 alignItems: 'center', 468 borderBottomColor: PURPLE_MAIN, 469 borderBottomWidth: 2, 470 backgroundColor: BLACK_PRIMARY471 }472});473const mapStateToProps = (state) => ({474 user: state.user,475 payment: state.payment476})...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

...45 x: 0,46 y: 0,47 image: imgFon,48 width: stage.getWidth(),49 height: stage.getHeight()50});51//VARIABLES DE CAIDA52var gravedad = 1;53var val_reb = 0;//0(no rebota el personaje con la superficie), 1(no regresa a su posicion original), >1(trampolin)54var bandera = false;55var juego = new Game();56var imgEn = new Image();57imgEn.src = "imagenes/enemy.png";58/*imgEn.onload = function(){59 //cargar cada imagen, xo no es necesario,60 //xq en el index.html, ya hemos añadido los assets durante la carga de la ventana,61 // a traves de Preload62}*/63var imgMon = new Image();64imgMon.src = "imagenes/moneda.png";65var imgLla = new Image();66imgLla.src = "imagenes/llave.png";67var imgPatt = new Image();68imgPatt.src = "imagenes/pattern.png";69var imgPuer = new Image();70imgPuer.src = "imagenes/puerta.png";71var imgH = new Image();72imgH.src = "imagenes/heroe-sprite.png";73var keyboard = {/*añadimos los event.keyCode con addKeyBoardEvents*/};74//LISTENERS75/*escuchar a cualquier tecla , xa mover un objeto*/76function addKeyBoardEvents(){77 document.addEventListener("keydown", function(event){78 keyboard[event.keyCode] = true;//asigna a todas las teclas. true79 }, false);80 document.addEventListener("keyup", function(event){81 keyboard[event.keyCode] = false;//una vez que se deje de presionar la tecla82 }, false);83}84//COLISIONES entre dos objetos85//usando las funciones de kinetic86function hit(a, b){87 //devuelve true si hay colision88 var hit = false;89 /*colision horizontal*/90 if(b.getX() + b.getWidth() >= a.getX() && b.getX() < a.getX() + a.getWidth()){91 /*colision vertical*/92 if(b.getY() + b.getHeight() >= a.getY() && b.getY() < a.getY() + a.getHeight()){93 hit = true;/*si ambas condiciones son verdaderas, colisionan*/94 }95 }96 /*colision entre a - b*/97 if(b.getX() <= a.getX() && b.getX() + b.getWidth() >= a.getX() + a.getWidth()){98 if(b.getY() <= a.getY() && b.getY() + b.getHeight() >= a.getY() + a.getHeight()){99 hit = true;100 }101 }102 /*colision entre b - a*/103 if(a.getX() <= b.getX() && a.getX() + a.getWidth() >= b.getX() + b.getWidth()){104 if(a.getY() <= b.getY() && a.getY() + a.getHeight() >= b.getY() + b.getHeight()){105 hit = true;106 }107 }108 return hit;109}110//PRIMERA CAPA DEL STAGE111function nivelUno(){112 juego.puntaje = 0;//reiniciamos el puntaje si volvemos al nivel 1113 if (bandera) return;114 bandera = true;115 //todos los objetos del nivel hay q agregarlos a la capa116 juego.llave = true;//el primer nivel esta abierta la llave117 fondo = new Kinetic.Layer();//propiedades deje la capa/escenario //LAYER118 /*ENEMIGOS, posiciones aleatorias*/119 grupoAssets.add(new Enemigo(150, stage.getHeight()-(300+60), imgEn));120 grupoAssets.add(new Enemigo(200, stage.getHeight()-60-15, imgEn));//enemmigo.height=60px;121 grupoAssets.add(new Enemigo(800, stage.getHeight()-(350+60), imgEn));122 grupoAssets.add(new Enemigo(700, stage.getHeight()-60-15, imgEn));123 grupoAssets.add(new Enemigo(1020, stage.getHeight()-75, imgEn));//fuera del lienzo124 grupoAssets.add(new Enemigo(1120, stage.getHeight()-75, imgEn));125 grupoAssets.add(new Enemigo(1220, stage.getHeight()-75, imgEn));126 grupoAssets.add(new Enemigo((stage.getWidth()*2)-30, (stage.getHeight()/3)-60, imgEn));127 grupoAssets.add(new Enemigo((stage.getWidth()*2)+30, stage.getHeight()-75, imgEn));128 /*PLATAFORMAS*/129 /*piso*/130 var piso = new Plataforma(0, stage.getHeight() - 15, imgPatt);131 piso.setWidth(stage.getWidth()*2);132 grupoAssets.add(piso);133 /*creamos cada plataforma, para cada enemigo, con instancias anonimas*/134 grupoAssets.add(new Plataforma(150, stage.getHeight()-(300), imgPatt));//+enemigo135 grupoAssets.add(new Plataforma(425, stage.getHeight()-125, imgPatt));136 grupoAssets.add(new Plataforma(575, stage.getHeight()-250, imgPatt));137 grupoAssets.add(new Plataforma(800, stage.getHeight()-(350), imgPatt));//+enemigo138 grupoAssets.add(new Plataforma(1020, stage.getHeight()-100, imgPatt));//fuera del lienzo139 grupoAssets.add(new Plataforma(1120, stage.getHeight()-100, imgPatt));140 grupoAssets.add(new Plataforma(1220, stage.getHeight()-100, imgPatt));141 grupoAssets.add(new Plataforma(1500, stage.getHeight()/2, imgPatt));142 grupoAssets.add(new Plataforma((stage.getWidth()*2)-30, stage.getHeight()/3, imgPatt));143 /*FIN PANTALLA*/144 grupoAssets.add(new PlataformaFin(stage.getWidth()*2, stage.getHeight(), 20, -stage.getHeight()/2, imgPatt));145 grupoAssets.add(new PlataformaFin(stage.getWidth()*2, stage.getHeight()/2, stage.getHeight()/2, 20, imgPatt));146 grupoAssets.add(new PlataformaFin((stage.getWidth()*2) + (stage.getHeight()/2), stage.getHeight(), 20, -stage.getHeight(), imgPatt));147 /*MONEDAS*/148 grupoAssets.add(new Moneda(200, stage.getHeight()-(350+30), imgMon));149 grupoAssets.add(new Moneda(300, stage.getHeight()-(175+30), imgMon));150 grupoAssets.add(new Moneda(500, stage.getHeight()-(50+30), imgMon));151 grupoAssets.add(new Moneda(610, stage.getHeight()-(250+30), imgMon));152 grupoAssets.add(new Moneda(850, stage.getHeight()-(350+30), imgMon));153 grupoAssets.add(new Moneda((800+40), stage.getHeight()-45, imgMon));154 grupoAssets.add(new Moneda(1220 + 150, stage.getHeight()-150, imgMon));155 grupoAssets.add(new Moneda(1220 + 200, stage.getHeight()-200, imgMon));156 grupoAssets.add(new Moneda(1220 + 250, stage.getHeight()-250, imgMon));157 /**/158 grupoAssets.add(new Moneda((stage.getWidth()*2)+60, stage.getHeight()-50, imgMon));159 grupoAssets.add(new Moneda((stage.getWidth()*2)+120, stage.getHeight()-50, imgMon));160 grupoAssets.add(new Moneda((stage.getWidth()*2)+180, stage.getHeight()-50, imgMon));161 /**/162 grupoAssets.add(new Moneda((stage.getWidth()*2)+80, stage.getHeight()-125, imgMon));163 grupoAssets.add(new Moneda((stage.getWidth()*2)+140, stage.getHeight()-125, imgMon));164 grupoAssets.add(new Moneda((stage.getWidth()*2)+200, stage.getHeight()-125, imgMon));165 /**/166 grupoAssets.add(new Moneda((stage.getWidth()*2)+60, stage.getHeight()-200, imgMon));167 grupoAssets.add(new Moneda((stage.getWidth()*2)+120, stage.getHeight()-200, imgMon));168 grupoAssets.add(new Moneda((stage.getWidth()*2)+180, stage.getHeight()-200, imgMon));169 /*PUERTA*/170 grupoAssets.add(new Puerta(810, stage.getHeight()-(70+15), imgPuer));171 grupoAssets.add(new Puerta(1750, stage.getHeight()-(70+15), imgPuer));172 /*HEROE*/173 //instanciamos la clase Heroe //SHAPE174 personaje = new Heroe(imgH, framesP);//framesP son las claves del sprite: javascript/heroe-sprite.js175 personaje.setX(30);176 personaje.setY(stage.getHeight() - personaje.getHeight() - 35);177 personaje.limiteDer = stage.getWidth() - personaje.getWidth();178 personaje.limiteTope = stage.getHeight() - piso.getHeight() - 15;//limite de abajo, del suelo179 /*STAGE / FONDO*/180 fondo.add(imagenFondo);181 fondo.add(personaje);//sobre el lienzo dibujamos el personaje182 fondo.add(grupoAssets);183 fondo.add(puntaje);184 personaje.start();//empieza a ejecutar la animacion del sprite185 //console.log(personaje);186 stage.add(fondo);//sobre el escenario le añadimos el lienzo o capa187 //CARGAMOS LOS FRAMES DENTRO DEL PIMER NIVEL, una vez se han cargado todas la imagnes188 var intv = setInterval(frameLoop, 1000/20);//se ejecuta la funcion 20 frames por segundo189 //funciones de intervalo de tiempo: que detecta los frames de imagenes190}191function nivelDos(){192 fondo = new Kinetic.Layer();//constructor de layer, fondo es la capa193 juego.llave = false;194 //Enemmigos195 grupoAssets.add(new Enemigo(200,stage.getHeight()/1.5-60,imgEn));196 grupoAssets.add(new Enemigo(850,stage.getHeight()/3.9-60,imgEn));197 grupoAssets.add(new Enemigo(25,stage.getHeight()/3-60,imgEn));198 grupoAssets.add(new Enemigo(500,stage.getHeight()-75,imgEn));199 grupoAssets.add(new Enemigo(650,stage.getHeight()-75,imgEn));200 grupoAssets.add(new Enemigo(850,stage.getHeight()-75,imgEn));201 //Puerta202 grupoAssets.add(new Puerta(1800-30,stage.getHeight()-90,imgPuer));203 //Plataformas204 var piso = new Plataforma(0,stage.getHeight()-15, imgPatt);205 piso.setWidth(stage.getWidth()*2);206 grupoAssets.add(piso);207 grupoAssets.add(new Plataforma(10,stage.attrs.height/3, imgPatt));208 grupoAssets.add(new Plataforma(190,stage.attrs.height/1.5, imgPatt));209 grupoAssets.add(new Plataforma(310,stage.attrs.height/4, imgPatt));210 grupoAssets.add(new Plataforma(550,stage.attrs.height/5, imgPatt));211 grupoAssets.add(new Plataforma(870,stage.attrs.height/3.9, imgPatt));212 //Llave213 var clau = new Llave(900, stage.getHeight()/7, imgLla);214 grupoAssets.add(clau);215 //Monedas216 grupoAssets.add(new Moneda(350,stage.getHeight()/3-130,imgMon));217 grupoAssets.add(new Moneda(200, stage.getHeight()-(350+30), imgMon));218 grupoAssets.add(new Moneda(300, stage.getHeight()-(175+30), imgMon));219 grupoAssets.add(new Moneda(500, stage.getHeight()-(50+30), imgMon));220 grupoAssets.add(new Moneda(610, stage.getHeight()-(250+30), imgMon));221 grupoAssets.add(new Moneda(850, stage.getHeight()-(350+30), imgMon));222 grupoAssets.add(new Moneda((800+40), stage.getHeight()-45, imgMon));223 grupoAssets.add(new Moneda(1220 + 150, stage.getHeight()-150, imgMon));224 grupoAssets.add(new Moneda(1220 + 200, stage.getHeight()-200, imgMon));225 grupoAssets.add(new Moneda(1220 + 250, stage.getHeight()-250, imgMon));226 //Personaje227 personaje = new Heroe(imgH,framesP);228 personaje.setX(30);229 personaje.setY(stage.getHeight() - personaje.getHeight() - 35);230 personaje.limiteDer = stage.getWidth() - personaje.getWidth();231 personaje.limiteTope = stage.getHeight() - piso.getHeight() - 15;232 fondo.add(imagenFondo);233 fondo.add(personaje);234 fondo.add(grupoAssets);235 fondo.add(puntaje);236 personaje.start();237 stage.add(fondo);238 var intv = setInterval(frameLoop, 1000/20);239}240function moverPersonaje(){//funciones de teclado para personaje241 if(personaje.getAnimation() != "caminar" && (keyboard[37] || keyboard[39])){242 personaje.setAnimation("caminar");243 }244 if(keyboard[37]){245 personaje.retroceder();246 }247 if(keyboard[39]){248 personaje.caminar();249 }250 if(keyboard[38] && personaje.contador < 1){//siempre y cuando el contador sea proximo a 0251 personaje.saltar();252 }253 if( !(keyboard[40] || keyboard[39] || keyboard[38] || keyboard[37]) && !personaje.estaSaltando){254 personaje.setAnimation("estatico");255 }256 for (var i = 0; i< grupoAssets.children.length; i++) {257 var plataforma = grupoAssets.children[i];258 if(keyboard[40] && !keyboard[37] && !keyboard[39] && personaje.getY() < plataforma.getY()){259 //aqui regulo la velocidad de caida260 personaje.vy+=0.3;261 }262 }263}264function moverFondo(){265 for (var i = 0; i< grupoAssets.children.length; i++) {266 var asset = grupoAssets.children[i];//movemos los assets para simular los movimientos267 if(personaje.getX() > (stage.getWidth()/2) && keyboard[39]){//que el personage sobrepase la pantalla y se este moviendo268 personaje.vx = 2;269 asset.move(-5, 0);270 }else{271 personaje.vx = 10;272 }273 }274}275function aplicarFuerzas(){276 personaje.aplicarGravedad(gravedad, val_reb);277}278function moverEnemigos(){279 //chikldfren atributo de kinetic que contiene el erreglo de todos los objetos instanciados con grupoAssets280 //recorremos enemigos281 for (var i in grupoAssets.children) {282 var enemigo = grupoAssets.children[i];283 //movemos solo los objetos enemigo de la clase Enemigo284 if(enemigo instanceof Enemigo){//devuelve true si la clase de enemigo es Enemigo (y no new Heroe o new Plataforma)285 enemigo.mover();286 }287 //ahora solo movemos la plataforma288 }289}290function ColisionPlataformas(){291 //var plataformas = grupoAssets.children();292 for (var i = 0; i< grupoAssets.children.length; i++) {293 var plataforma = grupoAssets.children[i];// va a ser cada uno de los assets del juego y donde se verifican las colisiones294 //funcion colisiones295 if(hit(plataforma, personaje)){296 //COLISION ENEMIGO297 if(plataforma instanceof Enemigo){298 //si caemos sobre el enemigoo299 if(personaje.vy > 2 && personaje.getY() < plataforma.getY()){//velocidad de caida suficiente = 2, y que el personaje este por encima del enemigo300 plataforma.remove();//eliminamos el enemigo301 juego.puntaje += 5;//si matamos enemigo nos hacemos con 5 puntos302 }else{//si nos lo topamos por otro lugar303 grupoAssets.removeChildren();304 document.querySelector("#score").innerHTML = juego.puntaje;305 document.querySelector("#lose").style.display = "block";306 document.querySelector("#game").style.display = "none";307 //window.clearInterval(intv);308 bandera = false;309 }310 }311 //COLISION PLATAFORMA y solo cuando esta cayendo312 else if(plataforma instanceof Plataforma && personaje.getY() < plataforma.getY() && personaje.vy >= 0){313 //detenga la caida314 personaje.contador = 0;315 personaje.setY(plataforma.getY() - personaje.getHeight() - 20);//el personaje se encontrara arriba de la plataforma316 personaje.vy = (personaje.vy * val_reb) + 35;//detener al personaje317 }318 else if(plataforma instanceof PlataformaFin && personaje.getX() < plataforma.getX()){319 personaje.setX(0);320 }321 //COLISION MONEDA322 else if(plataforma instanceof Moneda){323 plataforma.remove();324 juego.puntaje++;//se añada 2 pts325 }326 //COLISION LLAVE327 else if(plataforma instanceof Llave){328 plataforma.remove();329 juego.llave = true;...

Full Screen

Full Screen

cropzone.js

Source:cropzone.js Github

copy

Full Screen

...13 if (width+this.rect.getLeft() > canvas.fabric.getWidth()) {14 width = this.getOptimalDimensions().width;15 }16 this.rect.scaleToWidth(width);17 this.rect.setTop((canvas.fabric.getHeight() - this.rect.getHeight()) / 2);18 this.rect.setLeft((canvas.fabric.getWidth() - this.rect.getWidth()) / 2);19 this.rect.setCoords();20 this.drawGrid();21 this.drawOverlay();22 canvas.fabric.renderAll();23 },24 setHeight: function(height) {25 if (height < this.minHeight) {26 height = this.minHeight;27 }28 if (height > canvas.fabric.getHeight()) {29 height = this.getOptimalDimensions().height;30 }31 this.rect.scaleToHeight(height);32 this.rect.setTop((canvas.fabric.getHeight() - this.rect.getHeight()) / 2);33 this.rect.setLeft((canvas.fabric.getWidth() - this.rect.getWidth()) / 2);34 this.rect.setCoords();35 this.drawGrid();36 this.drawOverlay();37 canvas.fabric.renderAll();38 },39 add: function() {40 this.drawMainZone();41 this.drawOverlay();42 this.drawGrid();43 this.attachEvents();44 canvas.fabric.renderAll();45 this.initiated = true;46 $rootScope.$emit('cropzone.added');47 },48 constrainWithinCanvas: function(object) {49 var x = object.getLeft(), y = object.getTop();50 var w = object.getWidth(), h = object.getHeight();51 var maxX = canvas.fabric.getWidth() - w;52 var maxY = canvas.fabric.getHeight() - h;53 if (x < 0) {54 object.set('left', 0);55 }56 if (y < 0) {57 object.set('top', 0);58 }59 if (x > maxX) {60 object.set('left', maxX);61 }62 if (y > maxY) {63 object.set('top', maxY);64 }65 },66 constrainWithinCanvasOnScaling: function(object) {67 var minX = object.getLeft();68 var minY = object.getTop();69 var maxX = object.getLeft() + object.getWidth();70 var maxY = object.getTop() + object.getHeight();71 if (minX < 0 || maxX > canvas.fabric.getWidth()) {72 var lastScaleX = this.lastScaleX || 1;73 object.setScaleX(lastScaleX);74 }75 if (minX < 0) {76 object.setLeft(0);77 }78 if (minY < 0 || maxY > canvas.fabric.getHeight()) {79 var lastScaleY = this.lastScaleY || 1;80 object.setScaleY(lastScaleY);81 }82 if (minY < 0) {83 object.setTop(0);84 }85 if (object.getWidth() < this.minWidth) {86 object.width = this.minWidth;87 object.setScaleX(1);88 }89 if (object.getHeight() < this.minHeight) {90 object.height = this.minHeight;91 object.setScaleY(1);92 }93 this.lastScaleX = object.getScaleX();94 this.lastScaleY = object.getScaleY();95 },96 onMouseDown: function(event) {97 if (event.target && (event.target.name === 'cropzone' || event.target.name === 'crop.grid')) return;98 cropzone.dragging = true;99 //hide cropzone on single click on overlay100 cropzone.overlay.visible = false;101 cropzone.grid.visible = false;102 cropzone.rect.visible = false;103 //start position for drawing a cropzone104 cropzone.rect.left = event.e.pageX - canvas.fabric._offset.left;105 cropzone.rect.top = event.e.pageY - canvas.fabric._offset.top;106 //make sure cropzone scale is 1 for accurate coordinates107 cropzone.rect.scale(1);108 cropzone.overlay.scale(1);109 cropzone.grid.scale(1);110 cropzone.mousex = event.e.pageX;111 cropzone.mousey = event.e.pageY;112 //prevent selection of objects while dragging113 canvas.fabric.selection = false;114 cropzone.drawOverlay();115 },116 onMouseMove: function(event) {117 if ( ! cropzone.dragging) return;118 var width = event.e.pageX - cropzone.mousex,119 height = event.e.pageY - cropzone.mousey;120 //prevent cropzone going over the right edge121 if (canvas.offset.left + canvas.fabric.getWidth() < event.e.pageX) {122 width = (canvas.offset.left + canvas.fabric.getWidth()) - cropzone.mousex;123 }124 //left edge125 if (canvas.offset.left > event.e.pageX) {126 width = canvas.offset.left - cropzone.mousex;127 }128 //bottom edge129 if (canvas.offset.top + canvas.fabric.getHeight() < event.e.pageY) {130 height = (canvas.offset.top + canvas.fabric.getHeight()) - cropzone.mousey;131 }132 //top edge133 if (canvas.offset.top > event.e.pageY) {134 height = canvas.offset.top - cropzone.mousey;135 }136 cropzone.rect.width = width;137 cropzone.rect.height = height;138 cropzone.rect.moveTo(3);139 cropzone.rect.setCoords();140 cropzone.drawOverlay();141 cropzone.drawGrid();142 if ( ! cropzone.rect.visible) {143 cropzone.rect.visible = true;144 cropzone.overlay.visible = true;145 cropzone.grid.visible = true;146 }147 },148 onMouseUp: function() {149 cropzone.dragging = false;150 canvas.fabric.selection = true;151 cropzone.rect.setCoords();152 cropzone.grid.setCoords();153 cropzone.overlay.setCoords();154 if (cropzone.rect.visible) {155 canvas.fabric.setActiveObject(cropzone.rect);156 }157 },158 attachEvents: function() {159 //redraw cropzone grid and overlay when cropzone is resized160 this.rect.on('moving', function() {161 cropzone.constrainWithinCanvas(cropzone.rect);162 cropzone.drawOverlay();163 cropzone.drawGrid();164 });165 this.rect.on('scaling', function(e) {166 cropzone.constrainWithinCanvasOnScaling(cropzone.rect, e);167 cropzone.drawOverlay();168 cropzone.drawGrid();169 });170 canvas.fabric.on("mouse:down", cropzone.onMouseDown);171 canvas.fabric.on("mouse:move", cropzone.onMouseMove);172 canvas.fabric.on("mouse:up", cropzone.onMouseUp);173 },174 remove: function() {175 canvas.fabric.off("mouse:down", cropzone.onMouseDown);176 canvas.fabric.off("mouse:move", cropzone.onMouseMove);177 canvas.fabric.off("mouse:up", cropzone.onMouseUp);178 canvas.fabric.remove(this.rect);179 canvas.fabric.remove(this.grid);180 canvas.fabric.remove(this.overlay);181 canvas.fabric.renderAll();182 this.initiated = false;183 },184 hide: function() {185 this.rect.visible = false;186 this.rect.hasControls = false;187 this.grid.visible = false;188 this.overlay.visible = false;189 },190 getOptimalDimensions: function () {191 var width = canvas.fabric.getWidth() / 2,192 height = canvas.fabric.getHeight() / 2,193 left = canvas.fabric.getWidth() / 4,194 top = canvas.fabric.getHeight() / 4;195 if (canvas.viewport.offsetWidth < canvas.fabric.getWidth()) {196 width = canvas.viewport.offsetWidth / 2;197 left = canvas.viewport.offsetWidth / 4;198 }199 if (canvas.viewport.offsetHeight < canvas.fabric.getHeight()) {200 height = canvas.viewport.offsetHeight / 2;201 top = canvas.viewport.offsetHeight / 4;202 }203 return {width: width, height: height, left: left, top: top};204 },205 drawMainZone: function() {206 var dimensions = this.getOptimalDimensions();207 this.rect = new fabric.Rect({208 fill: 'transparent',209 stroke: 'rgba(255, 255, 255, 0.6)',210 hasBorders: false,211 width: dimensions.width,212 height: dimensions.height,213 left: dimensions.left,214 top: dimensions.top,215 hasRotatingPoint: false,216 name: 'cropzone',217 cornerColor: 'rgba(255, 255, 255, 0.6)',218 transparentCorners: false,219 ignore: true220 });221 canvas.fabric.add(this.rect);222 this.rect.moveTo(3);223 canvas.fabric.setActiveObject(cropzone.rect);224 },225 drawGrid: function() {226 if ( ! this.initiated) {227 this.line1 = new fabric.Line([], { stroke: 'rgba(255, 255, 255, 0.6)', strokeWidth: 1, selectable: false, evented: false });228 this.line2 = new fabric.Line([], { stroke: 'rgba(255, 255, 255, 0.6)', strokeWidth: 1, selectable: false, evented: false });229 this.line3 = new fabric.Line([], { stroke: 'rgba(255, 255, 255, 0.6)', strokeWidth: 1, selectable: false, evented: false });230 this.line4 = new fabric.Line([], { stroke: 'rgba(255, 255, 255, 0.6)', strokeWidth: 1, selectable: false, evented: false });231 this.grid = new fabric.Group([this.line1, this.line2, this.line3, this.line4]);232 this.grid.originY = 'left';233 this.grid.originX = 'top';234 this.grid.ignore = true;235 this.grid.selectable = false;236 canvas.fabric.add(this.grid);237 this.grid.moveTo(2);238 }239 this.grid.width = this.rect.getWidth();240 this.grid.height = this.rect.getHeight();241 this.grid.left = this.rect.getLeft();242 this.grid.top = this.rect.getTop();243 var width = cropzone.rect.getWidth() / 3,244 height = cropzone.rect.getHeight() / 3;245 this.line1.set({246 x1: width,247 y1: 0,248 x2: width,249 y2: cropzone.grid.getHeight(),250 });251 this.line2.set({252 x1: width * 2,253 y1: 0,254 x2: width * 2,255 y2: cropzone.grid.getHeight()256 });257 this.line3.set({258 x1: 0,259 y1: height,260 x2: cropzone.grid.getWidth(),261 y2: height262 });263 this.line4.set({264 x1: 0,265 y1: height * 2,266 x2: cropzone.grid.getWidth(),267 y2: height * 2268 });269 this.constrainWithinCanvas(this.grid);270 },271 drawOverlay: function() {272 if ( ! this.initiated) {273 this.topRect = new fabric.Rect({fill: 'rgba(0,0,0,0.7)', selectable: true, evented: false});274 this.rightRect = new fabric.Rect({fill: 'rgba(0,0,0,0.7)', selectable: true, evented: false});275 this.bottomRect = new fabric.Rect({fill: 'rgba(0,0,0,0.7)', selectable: true, evented: false});276 this.leftRect = new fabric.Rect({fill: 'rgba(0,0,0,0.7)', selectable: true, evented: false});277 this.overlay = new fabric.Group([this.topRect, this.rightRect, this.bottomRect, this.leftRect]);278 this.overlay.ignore = true;279 this.overlay.name = 'grid.overlay';280 canvas.fabric.add(this.overlay);281 this.overlay.moveTo(1);282 }283 this.topRect.set({284 left: 0,285 top: 0,286 width: canvas.fabric.width,287 height: this.rect.getHeight() < 0 ? this.rect.getTop() - Math.abs(this.rect.getHeight()) : this.rect.getTop(),288 });289 this.rightRect.set({290 left: this.rect.getWidth() < 0 ? this.rect.getLeft() : this.rect.getLeft() + this.rect.getWidth(),291 top: this.rect.getTop(),292 width: this.rect.getWidth() < 0 ? canvas.fabric.width - (this.rect.getLeft() + this.rect.getWidth()) - Math.abs(this.rect.getWidth()) : canvas.fabric.width - (this.rect.getLeft() + this.rect.getWidth()),293 height: this.rect.getHeight(),294 });295 this.bottomRect.set({296 left: 0,297 top: this.rect.getHeight() < 0 ? this.rect.getTop() : this.rect.getTop() + this.rect.getHeight(),298 width: canvas.fabric.width,299 height: this.rect.getHeight() < 0 ? canvas.fabric.height - (this.rect.getTop()) : canvas.fabric.height - (this.rect.getTop() + this.rect.getHeight()),300 });301 this.leftRect.set({302 left: 0,303 top: this.rect.getTop(),304 width: this.rect.getWidth() > 0 ? this.rect.getLeft() : this.rect.getLeft() - Math.abs(this.rect.getWidth()),305 height: this.rect.getHeight(),306 });307 }308 };309 return cropzone;...

Full Screen

Full Screen

teachStart.js

Source:teachStart.js Github

copy

Full Screen

...52 let rating = sessionData.userData.rating ? sessionData.userData.rating : 0;53 return (54 <Page>55 <View style={styles.container} >56 <Image style={{width: getWidth(155), height: getHeight(82)}} resizeMode={'contain'} source={ICON_LOGO}/>57 <View style={styles.modal}>58 <View style={{flex: 1, width: '100%', justifyContent: 'center', alignItems: 'center', paddingBottom: getHeight(40)}}>59 <Text style={styles.bodyText}>{this.props.sessionData.userData.userName}</Text>60 <View style={{flexDirection: 'row', justifyContent: 'center', alignItems: 'center'}}>61 {62 rating > 0 ?63 <Star width={getWidth(28)} height={getHeight(27)} color ={PURPLE_MAIN}/> :64 <BStar width={getWidth(28)} height={getHeight(27)} color={'#FFFFFF'} stroke={BLACK_PRIMARY} />65 }66 {67 rating > 1 ?68 <Star width={getWidth(28)} height={getHeight(27)} color ={PURPLE_MAIN}/> :69 <BStar width={getWidth(28)} height={getHeight(27)} color={'#FFFFFF'} stroke={BLACK_PRIMARY} />70 }71 {72 rating > 2 ?73 <Star width={getWidth(28)} height={getHeight(27)} color ={PURPLE_MAIN}/> :74 <BStar width={getWidth(28)} height={getHeight(27)} color={'#FFFFFF'} stroke={BLACK_PRIMARY} />75 }76 {77 rating > 3 ?78 <Star width={getWidth(28)} height={getHeight(27)} color ={PURPLE_MAIN}/> :79 <BStar width={getWidth(28)} height={getHeight(27)} color={'#FFFFFF'} stroke={BLACK_PRIMARY} />80 }81 {82 rating > 4 ?83 <Star width={getWidth(28)} height={getHeight(27)} color ={PURPLE_MAIN}/> :84 <BStar width={getWidth(28)} height={getHeight(27)} color={'#FFFFFF'} stroke={BLACK_PRIMARY} />85 }86 </View>87 88 </View>89 {/* <TouchableOpacity style={styles.btnBody}90 onPress={this._gotoHome}91 >92 {93 94 <Text style={styles.btnText}>95 {this.props.sessionData.name}'s Reviews96 </Text>97 </TouchableOpacity> */}98 </View>99 <BaseButton 100 text={'TEACH'}101 onClick={this._goTeach}102 buttonStyle={{marginTop: getHeight(185)}}103 />104 </View>105 </Page>106 107 )108 }109};110TeachStart.navigatorStyle = {111 navBarHidden: true,112 statusBarBlur: false113};114const styles = StyleSheet.create({115 container: {116 flex: 1,117 justifyContent: 'center',118 alignItems: 'center'119 },120 loadText: {121 paddingBottom: getHeight(10),122 color: '#FFFFFF',123 fontFamily: 'Montserrat-Bold',124 },125 modal: {126 width: getWidth(244),127 height: getHeight(262),128 backgroundColor: '#FFFFFF',129 alignItems: 'center',130 borderRadius: getHeight(10),131 marginTop: getHeight(42)132 },133 btnText: {134 fontFamily: 'Montserrat-Medium',135 color: '#FFFFFF',136 fontSize: getHeight(18)137 },138 bodyText: {139 fontFamily: 'Montserrat-Medium',140 fontSize: getHeight(20),141 color: BLACK_PRIMARY142 },143 bodySecText: {144 fontFamily: 'Montserrat-Medium',145 fontSize: getHeight(15),146 color: BLACK_PRIMARY147 },148 bodyThirdText: {149 fontFamily: 'Montserrat-Medium',150 fontSize: getHeight(18),151 color: BLACK_PRIMARY152 },153 btnBody: {154 width: getWidth(220), 155 height: getHeight(36), 156 borderRadius: getHeight(10), 157 backgroundColor: PURPLE_MAIN, 158 justifyContent: 'center',159 alignItems: 'center', 160 flexDirection: 'row',161 paddingLeft: getWidth(13),162 paddingRight: getWidth(25),163 marginBottom: getHeight(23)164 }165});166const mapStateToProps = (state) => ({167 user: state.user168})...

Full Screen

Full Screen

chSophist.js

Source:chSophist.js Github

copy

Full Screen

...39 return (40 <Page>41 <View style={styles.container}>42 <View style={styles.headView}>43 <Image width={getWidth(244)} height={getHeight(36)} source={WORD_LOGO} /> 44 </View>45 <View style={styles.mainView}>46 <View style={styles.modalView}>47 <View style={styles.modalMark}>48 <Hat width={getWidth(86)} height={getHeight(84)} color={BLACK_PRIMARY} /> 49 </View>50 <Image style={styles.modalLogoLeft} source={MARK_IMAGE} resizeMode={'contain'} />51 <Image style={styles.modalLogoRight} source={MARK_IMAGE} resizeMode={'contain'} />52 <View style={styles.modalTitleView}>53 <Text style={styles.modalTitle}>Abraham</Text>54 </View>55 <View style={styles.starView}>56 <Star width={getWidth(28)} height={getHeight(27)} color={BLACK_PRIMARY} />57 <Star width={getWidth(28)} height={getHeight(27)} color={BLACK_PRIMARY} />58 <Star width={getWidth(28)} height={getHeight(27)} color={BLACK_PRIMARY} />59 <Star width={getWidth(28)} height={getHeight(27)} color={BLACK_PRIMARY} />60 </View>61 <View style={styles.starView}>62 <Phone size={getHeight(18)} color={BLACK_PRIMARY}/>63 <Text style={styles.phoneNum}>(630)-772-***</Text>64 </View>65 <View style={styles.modalTimeView}>66 <Text style={styles.modalTime}>67 0:5768 </Text>69 </View>70 <View style={styles.modalBtnView}>71 <TouchableOpacity style={styles.modalBtn}>72 <Text style={styles.modalBtnText}>73 Abraham's Reviews74 </Text>75 </TouchableOpacity>76 </View>77 </View>78 </View>79 <View style={styles.btnView}>80 <BaseButton 81 text={'LEARN'}82 onClick={this.goForward}83 />84 </View>85 </View>86 </Page>87 88 )89 }90}91Final.navigatorStyle = {92 navBarHidden: false,93 statusBarBlur: false94}95const styles = StyleSheet.create({96 container: {97 flex: 1,98 width: '100%',99 height: '100%',100 justifyContent: 'center',101 alignItems: 'center'102 },103 headView: {104 height: getHeight(100),105 justifyContent: 'flex-end',106 alignItems: 'center'107 }, 108 mainView: {109 flex: 1,110 width: '100%',111 justifyContent: 'center',112 alignItems: 'center',113 },114 modalView:{115 backgroundColor: '#FFFFFF',116 width: getWidth(244),117 height: getHeight(262),118 borderRadius: getHeight(10),119 justifyContent: 'flex-start',120 alignItems: 'center'121 },122 modalLogoLeft:{123 width: getWidth(80),124 height: getHeight(67),125 position: 'absolute',126 top: 0,127 left: 0128 },129 modalLogoRight:{130 width: getWidth(80),131 height: getHeight(67),132 position: 'absolute',133 top: 0,134 right: 0135 },136 starView:{137 flexDirection: 'row',138 width: '100%',139 justifyContent: 'center',140 alignItems: 'center',141 marginBottom: getHeight(5)142 },143 btnView:{144 width: '100%',145 justifyContent: 'center',146 alignItems: 'center',147 height: getHeight(120)148 },149 modalMark: {150 marginTop: -getHeight(41),151 },152 modalTitleView:{153 width: '100%',154 justifyContent: 'center',155 alignItems: 'center',156 height: getHeight(36)157 },158 modalTitle: {159 fontFamily: 'Montserrat-Regular',160 fontSize: getHeight(20),161 color: BLACK_PRIMARY162 },163 phoneNum: {164 fontFamily: 'Montserrat-Regular',165 fontSize: getHeight(18),166 color: BLACK_PRIMARY,167 marginLeft: getWidth(12)168 },169 modalTimeView: {170 width: '100%',171 marginTop: getHeight(9),172 justifyContent: 'center',173 alignItems: 'center'174 },175 modalTime: {176 fontFamily: 'Montserrat-Regular',177 fontSize: getHeight(18),178 color: BLACK_PRIMARY179 },180 modalBtnView: {181 flex: 1,182 width: '100%',183 justifyContent: 'center',184 alignItems: 'center'185 },186 modalBtn: {187 width: getWidth(220),188 height: getHeight(36),189 backgroundColor: GRAY_PRIMARY,190 borderRadius: getHeight(10),191 justifyContent: 'center',192 alignItems: 'center'193 },194 modalBtnText: {195 fontFamily: 'Montserrat-Regular',196 fontSize: getHeight(18),197 color: '#FFFFFF'198 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 const developerName = Selector('#developer-name');4 const osOption = Selector('#macos');5 const submitButton = Selector('#submit-button');6 .typeText(developerName, 'John Smith')7 .click(osOption)8 .click(submitButton);9});10test('My second test', async t => {11 const getHeight = Selector(() => document.getElementById('height').value);12 .expect(getHeight()).eql('177');13});14test('My third test', async t => {15 const getHeight = Selector(() => document.getElementById('height').value);16 .expect(getHeight()).eql('177');17});18test('My fourth test', async t => {19 const getHeight = Selector(() => document.getElementById('height').value);20 .expect(getHeight()).eql('177');21});22test('My fifth test', async t => {23 const getHeight = Selector(() => document.getElementById('height').value);24 .expect(getHeight()).eql('177');25});26test('My sixth test', async t => {27 const getHeight = Selector(() => document.getElementById('height').value);28 .expect(getHeight()).eql('177');29});30test('My seventh test', async t => {31 const getHeight = Selector(() => document.getElementById('height').value);32 .expect(getHeight()).eql('177');33});34test('My eighth test', async t => {35 const getHeight = Selector(() => document.getElementById('height').value);36 .expect(getHeight()).eql('177');37});38test('My ninth test', async t => {39 const getHeight = Selector(() => document.getElementById('height').value);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 const button = Selector('#submit-button');4 .click(button)5 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');6});7import { Selector } from 'testcafe';8test('My first test', async t => {9 const button = Selector('#submit-button');10 .click(button)11 .expect(Selector('#article-header').getAttribute('class')).contains('result-content');12});13import { Selector } from 'testcafe';14test('My first test', async t => {15 const button = Selector('#submit-button');16 .click(button)17 .expect(Selector('#article-header').getBoundingClientRectProperty('width')).eql(700);18});19import { Selector } from 'testcafe';20test('My first test', async t

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 const element = Selector('#developer-name');4 .typeText(element, 'Peter')5 .click('#tried-test-cafe')6 .expect(element.value).eql('Peter');7 await t.expect(Selector('#submit-button').getAttribute('height')).eql('30');8});9const element = Selector('#submit-button');10const elementHeight = await element.getBoundingClientRectProperty('height');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2const testcafe = require('testcafe');3const { ClientFunction } = testcafe;4test('My first test', async t => {5 .typeText('#developer-name', 'John Smith')6 .click('#submit-button');7 const getLocation = ClientFunction(() => document.location.href);8 const height = await Selector('#article-header').getStyleProperty('height');9 console.log(height);10 console.log(await getLocation());11});12import { Selector } from 'testcafe';13const testcafe = require('testcafe');14const { ClientFunction } = testcafe;15test('My first test', async t => {16 .typeText('#developer-name', 'John Smith')17 .click('#submit-button');18 const getLocation = ClientFunction(() => document.location.href);19 const height = await Selector('#article-header').getStyleProperty('height');20 console.log(height);21 console.log(await getLocation());22});23import { Selector } from 'testcafe';24const testcafe = require('testcafe');25const { ClientFunction } = testcafe;26test('My first test', async t => {27 .typeText('#developer-name', 'John Smith')28 .click('#submit-button');29 const getLocation = ClientFunction(() => document.location.href);30 const height = await Selector('#article-header').getStyleProperty('height');31 console.log(height);32 console.log(await getLocation());33});34 3 passed (5s)

Full Screen

Using AI Code Generation

copy

Full Screen

1import {Selector} from 'testcafe';2test('My Test', async t => {3 const height = await Selector('#myElement').clientHeight;4 console.log(height);5});6import {Selector} from 'testcafe';7test('My Test', async t => {8 const height = await Selector('#myElement').clientHeight;9 console.log(height);10});111. Run the following command: `testcafe chrome test.js` (this should pass)122. Run the following command: `testcafe chrome test2.js` (this should fail)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Selector } = require('testcafe');2const getSelectorHeight = async (selector) => {3 const height = await Selector(selector).getStyleProperty('height');4 return height;5};6module.exports = getSelectorHeight;7const getSelectorHeight = require('./getSelectorHeight');8fixture('My Fixture')9test('My Test', async (t) => {10 const height = await getSelectorHeight('#tried-test-cafe');11 console.log(height);12});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector, t } from 'testcafe';2const test = Selector('test');3const height = await test.getHeight();4import { Selector, t } from 'testcafe';5const test = Selector('test');6const offsetTop = await test.getOffsetTop();7import { Selector, t } from 'testcafe';8const test = Selector('test');9const offsetLeft = await test.getOffsetLeft();10import { Selector, t } from 'testcafe';11const test = Selector('test');12const boundingClientRect = await test.getBoundingClientRect();13import { Selector, t } from 'testcafe';14const test = Selector('test');15const boundingClientRect = await test.getBoundingClientRect();16import { Selector, t } from 'testcafe';17const test = Selector('test');18const computedStyle = await test.getComputedStyle();19import { Selector, t } from 'testcafe';20const test = Selector('test');21const attribute = await test.getAttribute('attributeName');22import { Selector, t } from 'testcafe';23const test = Selector('test');24const hasAttribute = await test.hasAttribute('attributeName');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful