Fork me on GitHub
#clojurescript
<
2019-08-03
>
Aklscc11:08:40

Hey, everybody! I'm stuck in a problem of transfering javascript to clojurescript, and the code following:

javascript
import { createBottomTabNavigator, createStackNavigator, createAppContainer } from 'react-navigation';
....
const TabNavigator = createBottomTabNavigator({
  HomeScreen: {
    screen: HomeScreen,
    navigationOptions:({naviagtion}) => ({
      tabBarLabel: 'home',
      tabBarIcon: ({focused, tintColor}) => (
        <TabBarItem
          tintColor={tintColor}
          focused={focused}
          normalImage={require('./assets/home.png')}
          selectedImage={require('./assets/home.png')}
        />
      )
    })
  },
  Content: {
    screen: content,
    navigationOptions:({naviagtion}) => ({
      tabBarLabel: 'content',
      tabBarIcon: ({focused, tintColor}) => (
        <TabBarItem
          tintColor={tintColor}
          focused={focused}
          normalImage={require('./assets/content.png')}
          selectedImage={require('./assets/content.png')}
        />
      )
    })
  }
},
{
  tabBarOptions: {
    activeTintColor: '#4CB4E7',
    inactiveTintColor: '#FFEE93',
    style: {backgroundColor: '#FFC09F'}
  }
});

How can I transfer the code with `navigationOptions` to clojurescript?  It'a anonymous function as a `prop`, so maybe some difficult. And this is my effort, but the `tintColor` looks like unuseful.

clojure (ns react-navigation.core (:require [goog.object :as gobj])) (def ReactNavigation (js/require "react-navigation")) (def create-bottom-tabnavigator (gobj/get ReactNavigation #js ["createBottomTabNavigator"])) (def create-appcontainer (gobj/get ReactNavigation #js ["createAppContainer"])) (defn tab-navigator [] (router/create-bottom-tabnavigator (clj->js {:HomeScreen (clj->js {:screen (r/reactify-component home-screen) :navigationOptions (fn [{:keys [navigation]}] (clj->js {:tabBarLabel "首页" :tabBarIcon (fn [{:keys [focused, tintColor]}] (tabbar/tab-bar-item tintColor focused (js/require "../resources/assets/home.png") (js/require "../resources/assets/home.png")))}))}) :Content (clj->js {:screen (r/reactify-component content/content) :navigationOptions (fn [{:keys [navigation]}] (clj->js {:tabBarLabel "内容" :tabBarIcon (fn [{:keys [focused, tintColor]}] (tabbar/tab-bar-item tintColor focused (js/require "../resources/assets/content.png") (js/require "../resources/assets/content.png")))}))})}) (clj->js {:tabBarOptions {:activeTintColor "#4CB4E7" :inactiveTintColor "#FFEE93" :style {:backgroundColor "#FFC09F"}} }))) `

Aklscc11:08:52

I'm a rookie in clojurescript, give some references also can also have a huge effect.

Aklscc11:08:52
replied to a thread:Hey, everybody! I'm stuck in a problem of transfering javascript to clojurescript, and the code following: javascript import { createBottomTabNavigator, createStackNavigator, createAppContainer } from 'react-navigation'; .... const TabNavigator = createBottomTabNavigator({ HomeScreen: { screen: HomeScreen, navigationOptions:({naviagtion}) =&gt; ({ tabBarLabel: 'home', tabBarIcon: ({focused, tintColor}) =&gt; ( &lt;TabBarItem tintColor={tintColor} focused={focused} normalImage={require('./assets/home.png')} selectedImage={require('./assets/home.png')} /&gt; ) }) }, Content: { screen: content, navigationOptions:({naviagtion}) =&gt; ({ tabBarLabel: 'content', tabBarIcon: ({focused, tintColor}) =&gt; ( &lt;TabBarItem tintColor={tintColor} focused={focused} normalImage={require('./assets/content.png')} selectedImage={require('./assets/content.png')} /&gt; ) }) } }, { tabBarOptions: { activeTintColor: '#4CB4E7', inactiveTintColor: '#FFEE93', style: {backgroundColor: '#FFC09F'} } }); How can I transfer the code with `navigationOptions` to clojurescript? It'a anonymous function as a `prop`, so maybe some difficult. And this is my effort, but the `tintColor` looks like unuseful. clojure (ns react-navigation.core (:require [goog.object :as gobj])) (def ReactNavigation (js/require "react-navigation")) (def create-bottom-tabnavigator (gobj/get ReactNavigation #js ["createBottomTabNavigator"])) (def create-appcontainer (gobj/get ReactNavigation #js ["createAppContainer"])) (defn tab-navigator [] (router/create-bottom-tabnavigator (clj->js {:HomeScreen (clj->js {:screen (r/reactify-component home-screen) :navigationOptions (fn [{:keys [navigation]}] (clj->js {:tabBarLabel "首页" :tabBarIcon (fn [{:keys [focused, tintColor]}] (tabbar/tab-bar-item tintColor focused (js/require "../resources/assets/home.png") (js/require "../resources/assets/home.png")))}))}) :Content (clj->js {:screen (r/reactify-component content/content) :navigationOptions (fn [{:keys [navigation]}] (clj->js {:tabBarLabel "内容" :tabBarIcon (fn [{:keys [focused, tintColor]}] (tabbar/tab-bar-item tintColor focused (js/require "../resources/assets/content.png") (js/require "../resources/assets/content.png")))}))})}) (clj->js {:tabBarOptions {:activeTintColor "#4CB4E7" :inactiveTintColor "#FFEE93" :style {:backgroundColor "#FFC09F"}} }))) ```

I'm a rookie in clojurescript, give some references also can also have a huge effect.

Abhinav Sharma20:08:40

Guys, does anyone know how to translate this console.log('\x1b[36m%s\x1b[0m', 'I am cyan') into ClojureScript ? What I've tried is (console.log '\x1b[36m%s\x1b[0m', 'I am cyan') which throws an error regarding the escape sequences.

Abhinav Sharma21:08:20

Solved it: If anyone else is wondering the same, then here's the code

;; Reference: 

(def ascii-colors
  {:red "\u001b[31m"
   :green "\u001b[32m"
   :yellow "\u001b[33m"
   :blue "\u001b[34m"
   :magenta "\u001b[35m"
   :cyan "\u001b[36m"
   :white "\u001b[37m"
   :reset "\u001b[0m"})

(defn colorized-log [color text]
  (str ((keyword color) ascii-colors) text (:reset ascii-colors)))

(colorized-log "red" "This is colored!")



Abhinav Sharma21:08:20

Solved it: If anyone else is wondering the same, then here's the code

;; Reference: 

(def ascii-colors
  {:red "\u001b[31m"
   :green "\u001b[32m"
   :yellow "\u001b[33m"
   :blue "\u001b[34m"
   :magenta "\u001b[35m"
   :cyan "\u001b[36m"
   :white "\u001b[37m"
   :reset "\u001b[0m"})

(defn colorized-log [color text]
  (str ((keyword color) ascii-colors) text (:reset ascii-colors)))

(colorized-log "red" "This is colored!")