Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
Remove deprecated code (#219)
Browse files Browse the repository at this point in the history
* removed deprecated code

* remove deprecated code

* Removed deprecated interface Beagle-screen

* Removed deprecated networkOptions

* Removed deprecated code from react-native

* Removed Beagle-screen-model

* Requested changes

* requested changes

* requested changes

Co-authored-by: tayronearaujo <[email protected]>
Co-authored-by: Tiago Peres França <[email protected]>
  • Loading branch information
3 people authored Sep 10, 2021
1 parent bbc3e62 commit 0e1a9d9
Show file tree
Hide file tree
Showing 55 changed files with 73 additions and 1,388 deletions.
13 changes: 2 additions & 11 deletions packages/beagle-react-native/src/components/BeagleButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* limitations under the License.
*/

import React, { FC, useContext } from 'react'
import BeagleServiceContext from 'common/provider'
import React, { FC } from 'react'
import { BeagleButtonInterface } from 'common/models'
import { Button, View } from 'react-native'
import { ViewContentManager } from 'common/types'
Expand All @@ -42,19 +41,11 @@ const BeagleButton: FC<BeagleButtonInterface> = ({
onPress,
style,
viewContentManager,
clickAnalyticsEvent,
enabled = true,
accessibility,
}) => {
const beagleService = useContext(BeagleServiceContext)
const isSubmit = isSubmitButton(viewContentManager)
const beagleAnalytics = beagleService && beagleService.analytics
const handlePress = () => {
if (clickAnalyticsEvent && beagleAnalytics)
beagleAnalytics.trackEventOnClick(clickAnalyticsEvent)

return isSubmit ? submitForm() : onPress && onPress()
}
const handlePress = () => isSubmit ? submitForm() : onPress && onPress()

return (
<View style={style}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,15 @@
* limitations under the License.
*/

import React, { FC, useEffect, useContext } from 'react'
import React, { FC, useEffect } from 'react'
import { BeagleContainerInterface } from 'common/models'
import { View } from 'react-native'
import BeagleServiceContext from 'common/provider'

const BeagleContainer: FC<BeagleContainerInterface> = props => {
const beagleService = useContext(BeagleServiceContext)
const { children, style, onInit, screenAnalyticsEvent } = props
const beagleAnalytics = beagleService && beagleService.analytics
const { children, style, onInit } = props

useEffect(() => {
if (screenAnalyticsEvent && beagleAnalytics)
beagleAnalytics.trackEventOnScreenAppeared(screenAnalyticsEvent)
if (onInit) onInit()
return () => {
if (screenAnalyticsEvent && beagleAnalytics)
beagleAnalytics.trackEventOnScreenDisappeared(screenAnalyticsEvent)
}
}, [])

return <View style={style}>{children}</View>
Expand Down
26 changes: 5 additions & 21 deletions packages/beagle-react-native/src/components/BeagleLazy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,13 @@
* limitations under the License.
*/

import React, { FC, useEffect } from 'react'
import { LoadParams } from '@zup-it/beagle-web'
import { View } from 'react-native'
import { BeagleLazyInterface } from 'common/models'
// todo: implement this according to the new ViewClient API

const BeagleLazy: FC<BeagleLazyInterface> = ({ path, children, viewContentManager }) => {
useEffect(() => {
const params: LoadParams = {
path,
shouldShowLoading: false,
}
viewContentManager && viewContentManager.getView().fetch(
params,
viewContentManager.getElementId(),
'replaceComponent',
)
}, [])
import { FC } from 'react'

return (
<View>
{children}
</View>
)
const BeagleLazy: FC = () => {
throw new Error('Not implemented yet')
}

export default BeagleLazy

100 changes: 3 additions & 97 deletions packages/beagle-react-native/src/components/BeagleListView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,104 +14,10 @@
* limitations under the License.
*/

import React, { FC, useEffect, useMemo, useRef, useState } from 'react'
import { BeagleListViewInterface } from 'common/models'
import { ScrollView, StyleSheet, NativeScrollEvent } from 'react-native'
import { renderListViewDynamicItems } from 'common/utils/listview'
import { FC } from 'react'

const BeagleListView: FC<BeagleListViewInterface> = ({
dataSource,
direction,
template,
templates,
__suffix__,
_key,
children,
className,
iteratorName = 'item',
onInit,
onScrollEnd,
scrollEndThreshold = 100,
style,
useParentScroll,
viewContentManager,
}) => {
const scrollRef = useRef(null)
const templatesRaw: BeagleListViewInterface['templates'] =
useMemo(() =>
viewContentManager ? viewContentManager.getElement().templates : undefined,
[JSON.stringify(dataSource), templates])
const horizontal = direction && direction === 'HORIZONTAL'
const styleSheet = StyleSheet.create({
fromBffStyles: {
...style,
},
defaultStyles: {
flex: style && style.flex ? Number(style.flex) : 1,
borderWidth: 1,
borderColor: '#000000',
borderStyle: 'solid',
},
})

const [shouldLoadPage, setShouldLoadPage] = useState(true)

useEffect(() => {
onInit && onInit() || onScrollEnd && onScrollEnd()
}, [])

useEffect(() => {
renderListViewDynamicItems(
dataSource,
viewContentManager,
template,
templatesRaw,
_key,
__suffix__,
iteratorName
)
setShouldLoadPage(true)
}, [JSON.stringify(dataSource)])

const hasReachedEndOfList = ({
contentOffset,
layoutMeasurement,
contentSize }: NativeScrollEvent) => {

let offset = contentOffset.y
let layoutSize = layoutMeasurement.height
let listSize = contentSize.height
if (direction === 'HORIZONTAL') {
offset = contentOffset.x
layoutSize = layoutMeasurement.width
listSize = contentSize.width
}
const sizeSum = offset + layoutSize

return Math.round(sizeSum) >= Math.round(listSize * scrollEndThreshold / 100)
}

function callOnEndAction(nativeEvent: NativeScrollEvent) {
if (hasReachedEndOfList(nativeEvent) && shouldLoadPage) {
setShouldLoadPage(false)
onScrollEnd && onScrollEnd()
}
}

return (
<ScrollView
ref={scrollRef}
onScroll={({ nativeEvent }) => callOnEndAction(nativeEvent)}
scrollEventThrottle={1000}
style={
{
...styleSheet.defaultStyles,
...styleSheet.fromBffStyles,
}}
horizontal={horizontal}>
{children}
</ScrollView>
)
const BeagleListView: FC = () => {
throw Error('The listView component is not implemented yet')
}

export default BeagleListView
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,17 @@
* limitations under the License.
*/

import React, { FC, useContext } from 'react'
import BeagleServiceContext from 'common/provider'
import React, { FC } from 'react'
import { BeagleTouchableInterface } from 'common/models'
import { TouchableOpacity, StyleSheet, View } from 'react-native'


const BeagleTouchable: FC<BeagleTouchableInterface> = ({
onPress,
clickAnalyticsEvent,
style,
children,
}) => {
const beagleService = useContext(BeagleServiceContext)
const beagleAnalytics = beagleService && beagleService.analytics
const handlePress = () => {
if (clickAnalyticsEvent && beagleAnalytics)
beagleAnalytics.trackEventOnClick(clickAnalyticsEvent)
return onPress && onPress()
}
const handlePress = () => onPress && onPress()

const styleSheet = StyleSheet.create({
fromBffStyles: {
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions packages/beagle-react-native/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import BeagleTextInput from './BeagleInput'
import BeagleTouchable from './BeagleTouchable'
import BeagleTabBar from './BeagleTabBar'
import BeaglePageView from './BeaglePageView'
import BeaglePageIndicator from './PageIndicator'
import BeagleLazy from './BeagleLazy'
import BeagleSimpleForm from './BeagleSimpleForm'
import BeagleWebView from './BeagleWebView'
Expand All @@ -46,7 +45,6 @@ const beagleDefaultComponents = {
'beagle:touchable': BeagleTouchable,
'beagle:tabbar': BeagleTabBar,
'beagle:pageview': BeaglePageView,
'beagle:pageIndicator': BeaglePageIndicator,
'beagle:lazycomponent': BeagleLazy,
'beagle:simpleform': BeagleSimpleForm,
'beagle:webview': BeagleWebView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ const mockStyle: React.CSSProperties = {

configure({ adapter: new Adapter() })
beforeAll(() => {
wrapper = shallow(<BeagleGridView
numColumns={5}
style={mockStyle}
wrapper = shallow(<BeagleGridView
style={mockStyle}
dataSource={['testA', 'testB', 'testC']}
template={{ _beagleComponent_: 'beagle:text', text: '@item' }}
templates={[{
view: {
_beagleComponent_: 'beagle:container',
children: [
{
_beagleComponent_: 'beagle:text',
text: '@item'
}
],
},
}]}
className='Test Class' />)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ let wrapper: any
const beagleInputPropsMock: BeagleTextInputInterface = {
value: 'Testing',
placeholder: 'Testing',
disabled: false,
enabled: true,
readOnly: false,
type: 'TEXT',
Expand Down Expand Up @@ -70,7 +69,6 @@ test('Should update text on input', () => {
const wrapper = mount(
<BeagleInput
value={inputStateValue}
disabled={false}
readOnly={false}
placeholder="Testing"
type="TEXT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,6 @@ const mockStyle: React.CSSProperties = {

configure({ adapter: new Adapter() })

/**
* @deprecated since v1.9.0 Will be removed in 2.0. Use templates instead.
*/
describe('Render BeagleListView with template', () => {
beforeAll(() => {
wrapper = shallow(
<BeagleListView
direction={directionMock}
style={mockStyle}
dataSource={['testA', 'testB', 'testC']}
template={{ _beagleComponent_: 'beagle:text', text: '@item' }}
className="Test Class"
/>
)
})

test('Beagle snapshot list view', () => {
expect(wrapper).toMatchSnapshot()
})
})

describe('Render BeagleListView with multiple templates', () => {
const dataSource = [
{ key: 'first', text: 'First Child' },
Expand Down
Loading

0 comments on commit 0e1a9d9

Please sign in to comment.